What is this and why?!
I want to show you my library for work with BitShares blockchain write on JavaScript. Exactly, this wrapper for official bitshares.js.
Why I decided write this, if have bitshares.js?!
It is not so usable for my projects, as I would like. Solving their private problems, after some time, it became clear that the code is growing and not very convenient. Decided to unify several repetitive parts in different projects to bring everything into one package. And as this package was being written, there was a desire to make it more universal and convenient. So BTSDEX appeared.
Implementation
The main class in the package is BitShares. All you need is in it. There are a couple more helper classes, but they are not really designed for use outside of the BitShares class. Perhaps at some next version this will change.
The BitShares class consists of static methods intended for working with the BitShares public blockchain API. Using the BitShares class, you can create an object whose methods provide access to the private part of the BitShares blockchain API.
The package is distributed under the MIT license. Link to github!
How to install:
$ npm install btsdex
Requre in your project:
const BitShares = require("btsdex");
Some examples
To connect to the BitShares network, you must initialize and connect:
BitShares.init("wss://bitshares.openledger.info/ws")
await BitShares.connect();
Public API
After the connection, you can use any public method from official documentation (if the method is still relevant!).
Database API
To access the Database API, you can use the BitShares.db object.
An example of methods from the Database API:
get_objects (const vector <object_id_type> & ids) const
list_assets (const string & lower_bound_symbol, uint32_t limit) const
To use them:
let obj = await BitShares.db.get_objects(["1.3.0"])
let bts = await BitShares.db.list_assets("BTS", 100)
History API
To access the Account History API, you can use the BitShares.history object.
Example of a method from the Account History API:
get_account_history (account_id_type account, operation_history_id_type stop = operation_history_id_type (), unsigned limit = 100, operation_history_id_type start = operation_history_id_type ()) const
To use it:
let ops = await BitShares.history.get_account_history("1.2.849826", "1.11.0", 10, "1.11.0")
Private API
If you want to have access to account operations, you need to create a BitShares object:
let bot = new BitShares("accountName", "privateActiveKey")
While this object can not much: buy, sell, transfer, cancel orders.
Signatures of methods:
bot.buy(buySymbol, baseSymbol, amount, price, fill_or_kill = false, expire = "2020-02-02T02: 02: 02")
bot.sell(sellSymbol, baseSymbol, amount, price, fill_or_kill = false, expire = "2020-02-02T02: 02: 02")
bot.cancelOrder(id)
bot.transfer(toName, assetSymbol, amount, memo)
Examples of using:
await bot.buy("OPEN.BTC", "BTS", 0.002, 140,000)
await bot.sell("BTS", "USD", 187, 0.24)
await bot.transfer("scientistnik", "BTS", 10)
If you want to send tokens with memo, then before that you need to set a private memo-key:
bot.setMemoKey("privateMemoKey")
await bot.transfer("scientistnik", "USD", 10, "Thank you for BTSDEX!")
Helper classes
There are a couple more helper classes, such as BitShares.assets and BitShares.accounts:
let usd = await BitShares.assets.usd;
let btc = await BitShares.assets["OPEN.BTS"];
let bts = await BitShares.assets["bts"];
let iam = await BitShares.accounts.scientistnik;
let tradebot = await BitShares.accounts["trade-bot"];
The returned objects contain all the fields that blockchain returns when the given asset or account name is requested.
What's Next
In the current version, I personally do not have enough convenient mechanism for requesting the cost of various transactions and subscribing to various changes in the blockchain. In the official bitshares.js there is an implementation of this, but it is not very convenient as for me. Most likely I will use it, but writing some wrapper on top.
If you have any other suggestions, you can write me! I always open to dialogue!
Thank you for your attention and see you soon!
Great work, are you already in the community groups (Telegram/Discord)? Perhaps you'll find good suggestions there also :)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Which groups did you mean?
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hey. Very nice wrapper.
Can you add some little examples to your library that just work out of the box. E.g. I'm interested in doing transfers.
Thanks J
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
For example:
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hey.
I had nearly the same code but it failed due to an old npm version dependency problems. But I got it to work.
Thanks J
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Hey .... I did not get 10 BTS!!!
I'm kidding))
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Great work, keep it up! :)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
I took some programming classes a long time ago but Im not much of a programmee. Will this information help bitshare grow and the coin appreciate?
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
I would like to believe)
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @scientistnik!
Your post was mentioned in the Steemit Hit Parade for newcomers in the following category:
I also upvoted your post to increase its reward
If you like my work to promote newcomers and give them more visibility on Steemit, feel free to vote for my witness! You can do it here or use SteemConnect
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Good job @scientistnik!!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
you excellent devloper ! !! i hav followed you !!
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Excellent Work! Very convenient library!
As possible memoDecode after tx history? Then the library will be indispensable in use.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
yes
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit