create account

[ANN] SteemJS (steemjs-lib) by svk

View this thread on: hive.blogpeakd.comecency.com
· @svk ·
$701.28
[ANN] SteemJS (steemjs-lib)
## Need more Javascript
Since we still don't have an open-source Javascript library for constructing and signing transactions, I've spent some time over the last week to build one, starting from [graphenejs-lib](https://github.com/svk31/graphenejs-lib). The result is now out on NPM and Github and can be used to quickly and easily create bots using Node.js, or to start building custom trading solutions or posting platforms. The library can be installed with npm or cloned from github:
  
```
npm install steemjs-lib
```
[https://github.com/svk31/steemjs-lib](https://github.com/svk31/steemjs-lib)

![Crypto tests screenshot](https://ipfs.pics/ipfs/QmQFmmJ2VrF1rAjkVftyNLd8i5bzGzWNP31pLaUAHFsPed?dl=1)

I will be releasing some specific use cases in the near future (who wants a "vote-as" bot?), and I might also use this to integrate actual trading in my [Live market page](https://steemit.com/steem/@svk/live-market-page). For now however the easiest way to figure out how to use it is to look at the tests, which can be found [here](https://github.com/svk31/steemjs-lib/tree/master/test). 

## Usage

Three sub-libraries are included: `ECC`, `Chain` and `Serializer`. Generally only the `ECC` and `Chain` libraries need to be used directly.

### Chain
The Chain library contains utility functions related to the chain state, as well as a transaction builder and a login class.

#### Transaction builder
The transaction builder can be used to construct any transaction, sign it, and broadcast it. To broadcast a transaction you need to be connected to a `steemd` node with the `network_broadcast_api` enabled.

For an example of how to create transaction, see below:

```
let login = new Login();
let tr = new TransactionBuilder();
tr.add_type_operation("vote", {
    voter: "myaccount,
    author: "seshadga",
    permlink: "bitcoin-price-sustainability-looks-on-track",
    weight: 100
});

tr.process_transaction(login, null, false);
```

The third argument is `process_transaction` is `broadcast`. Setting it to false will simply construct the transaction and serialize it, without broadcasting it.

#### Login
The Chain library includes the Login class that can be used to "log in" using an account name and a corresponding password or private key. Logging in here simply means verifying that the private key or password provided can be used to generate the private key for that account. The verification checks the public keys of the given account.

The password used on [https://steemit.com](https://steemit.com) is compatible with this library. To run the Login tests, copy config.example.js and create a config.js. In this file you must provide two accounts, one with a password and one with a private key. The corresponding public keys can be found on [https://steemd.com](https://steemd.com).

The Login class uses the following format to generate private keys from account names and passwords:

```
keySeed = accountName + role + password
```
Where `role` can be one of `active, owner, posting, memo`.

Using this seed, private keys are generated for either the default roles `active, owner, posting, memo`, or as specified. A minimum password length of 12 characters is enforced, but an even longer password is recommended. Three methods are provided:

```
generateKeys(account, password, [roles])
fromPrivKey(accountName, privateKey, [roles])
checkKeys({accountName, password, privateKey, auths})
signTransaction(tr)
getRoles()
setRoles([roles])
```

The auths object should contain the auth arrays from the account object. An example is this:

```
{
    active: [
        ["GPH5Abm5dCdy3hJ1C5ckXkqUH2Me7dXqi9Y7yjn9ACaiSJ9h8r8mL", 1]
    ]
}
```

If checkKeys is successful, you can use signTransaction to sign a TransactionBuilder transaction using the private keys for that account.
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 190 others
properties (23)
authorsvk
permlinkann-steemjs-steemjs-lib
categorysteem
json_metadata{"tags":["steem","crypto","bots"],"links":["https://github.com/svk31/graphenejs-lib"]}
created2016-07-11 20:39:00
last_update2016-07-11 20:39:00
depth0
children11
last_payout2016-08-23 12:26:45
cashout_time1969-12-31 23:59:59
total_payout_value681.426 HBD
curator_payout_value19.854 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3,802
author_reputation28,721,479,690,952
root_title"[ANN] SteemJS (steemjs-lib)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id80,600
net_rshares199,095,595,069,688
author_curate_reward""
vote details (254)
@arwani-wawan ·
thanks , let's go
this my information about bitcoin
https://steemit.com/bitcoin/@arwani-wawan/bitcoin-core-version-0-12-1-is-now-available
👍  
properties (23)
authorarwani-wawan
permlinkre-svk-ann-steemjs-steemjs-lib-20160711t224633974z
categorysteem
json_metadata{"tags":["steem"],"links":["https://steemit.com/bitcoin/@arwani-wawan/bitcoin-core-version-0-12-1-is-now-available"]}
created2016-07-11 22:46:33
last_update2016-07-11 22:46:33
depth1
children0
last_payout2016-08-23 12:26:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length138
author_reputation1,778,169,012,577
root_title"[ANN] SteemJS (steemjs-lib)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id81,195
net_rshares57,256,821
author_curate_reward""
vote details (1)
@dicov ·
Nice
properties (22)
authordicov
permlinkre-svk-ann-steemjs-steemjs-lib-20160712t101743547z
categorysteem
json_metadata{"tags":["steem"]}
created2016-07-12 10:17:42
last_update2016-07-12 10:17:42
depth1
children0
last_payout2016-08-23 12:26:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length4
author_reputation1,440,584,959,387
root_title"[ANN] SteemJS (steemjs-lib)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id84,439
net_rshares0
@ethereums1 ·
perfectly and check that you have gathered here, too)
properties (22)
authorethereums1
permlinkre-svk-ann-steemjs-steemjs-lib-20160712t181708670z
categorysteem
json_metadata{"tags":["steem"]}
created2016-07-12 18:17:06
last_update2016-07-12 18:17:06
depth1
children0
last_payout2016-08-23 12:26:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length53
author_reputation89,020,079,608
root_title"[ANN] SteemJS (steemjs-lib)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id87,031
net_rshares0
@fusan ·
Grate!
Wonderful Javascript world!
👍  ,
properties (23)
authorfusan
permlinkre-svk-ann-steemjs-steemjs-lib-20160712t025209656z
categorysteem
json_metadata{"tags":["steem"]}
created2016-07-12 02:52:09
last_update2016-07-12 02:52:09
depth1
children0
last_payout2016-08-23 12:26:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length34
author_reputation13,477,391,966,419
root_title"[ANN] SteemJS (steemjs-lib)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id82,418
net_rshares837,769,118
author_curate_reward""
vote details (2)
@gekko ·
some js love is good for us, thanks @svk !
👍  
properties (23)
authorgekko
permlinkre-svk-ann-steemjs-steemjs-lib-20160721t002929558z
categorysteem
json_metadata{"tags":["steem"],"users":["svk"]}
created2016-07-21 00:29:30
last_update2016-07-21 00:29:30
depth1
children0
last_payout2016-08-23 12:26:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length42
author_reputation1,185,517,433,922
root_title"[ANN] SteemJS (steemjs-lib)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id234,273
net_rshares193,476,386
author_curate_reward""
vote details (1)
@joelinux ·
Wow thats cool
👍  
properties (23)
authorjoelinux
permlinkre-svk-ann-steemjs-steemjs-lib-20160711t215246523z
categorysteem
json_metadata{"tags":["steem"]}
created2016-07-11 21:52:45
last_update2016-07-11 21:52:45
depth1
children0
last_payout2016-08-23 12:26:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length14
author_reputation4,604,092,068,298
root_title"[ANN] SteemJS (steemjs-lib)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id80,934
net_rshares57,256,821
author_curate_reward""
vote details (1)
@kenny-crane ·
This is great!

I'm researching the different ways of programmatically interacting with the steem blockchain and will add this to my list of things to study.  I'm wondering how this compares with an existing steemjs at https://github.com/pharesim/steemjs  

I do prefer js code to python since I have done a lot of work with it.  Do you think one language is better than the other, or just a matter of preference?

Thanks for your work on this, and for sharing it!
👍  , , ,
properties (23)
authorkenny-crane
permlinkre-svk-ann-steemjs-steemjs-lib-20160711t211129703z
categorysteem
json_metadata{"tags":["steem"],"links":["https://github.com/pharesim/steemjs"]}
created2016-07-11 21:11:30
last_update2016-07-11 21:11:30
depth1
children2
last_payout2016-08-23 12:26:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length464
author_reputation235,849,145,602,521
root_title"[ANN] SteemJS (steemjs-lib)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id80,759
net_rshares164,855,241,333
author_curate_reward""
vote details (4)
@svk ·
Thanks.

I have a [websocket rpc library](https://steemit.com/steem/@svk/steem-rpc-library-for-javascript-steem-rpc) available also that can be compared to pharesim's steemjs. This new library `steemjs-lib` provides completely different functionality as it lets you construct and sign transactions without needing the cli_wallet. You need a running `steemd` to broadcast transactions, but that could be a public one like xeroc's wss://this.piston.rocks.
👍  , , ,
properties (23)
authorsvk
permlinkre-kenny-crane-re-svk-ann-steemjs-steemjs-lib-20160711t213833195z
categorysteem
json_metadata{"tags":["steem"],"links":["https://steemit.com/steem/@svk/steem-rpc-library-for-javascript-steem-rpc"]}
created2016-07-11 21:38:33
last_update2016-07-11 21:38:33
depth2
children1
last_payout2016-08-23 12:26:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length453
author_reputation28,721,479,690,952
root_title"[ANN] SteemJS (steemjs-lib)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id80,881
net_rshares241,927,222,456
author_curate_reward""
vote details (4)
@kenny-crane ·
Thanks for your excellent answer!  I'm not there yet on a complete understanding, but I am getting there!
👍  
properties (23)
authorkenny-crane
permlinkre-svk-re-kenny-crane-re-svk-ann-steemjs-steemjs-lib-20160712t002748949z
categorysteem
json_metadata{"tags":["steem"]}
created2016-07-12 00:27:48
last_update2016-07-12 00:27:48
depth3
children0
last_payout2016-08-23 12:26:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length105
author_reputation235,849,145,602,521
root_title"[ANN] SteemJS (steemjs-lib)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id81,777
net_rshares62,028,223
author_curate_reward""
vote details (1)
@mjgrae ·
Awesome! I'm gonna give this a go later tonight with some silly experiments.

JavaScript never fails to make a quick and interesting entrance to any scene.
properties (22)
authormjgrae
permlinkre-svk-ann-steemjs-steemjs-lib-20160713t183112645z
categorysteem
json_metadata{"tags":["steem"]}
created2016-07-13 18:31:12
last_update2016-07-13 18:31:12
depth1
children0
last_payout2016-08-23 12:26:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length155
author_reputation1,247,707,052,821
root_title"[ANN] SteemJS (steemjs-lib)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,807
net_rshares0
@xeroc ·
$1.68
Very good job!
👍  , , , , ,
properties (23)
authorxeroc
permlinkre-svk-ann-steemjs-steemjs-lib-20160711t204344145z
categorysteem
json_metadata{"tags":["steem"]}
created2016-07-11 20:43:48
last_update2016-07-11 20:43:48
depth1
children0
last_payout2016-08-23 12:26:45
cashout_time1969-12-31 23:59:59
total_payout_value1.398 HBD
curator_payout_value0.285 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length14
author_reputation118,819,064,085,695
root_title"[ANN] SteemJS (steemjs-lib)"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id80,623
net_rshares7,863,830,207,925
author_curate_reward""
vote details (6)