Posts

Steem-tx | Lightweight JavaScript library for creating and signing transactions on the Steem blockchain

avatar of @mahdiyari
25
@mahdiyari
·
0 views
·
2 min read

steem-tx-js

Lightweight JavaScript library for creating, signing, and broadcasting transactions on the Steem blockchain


Important: As this post gets older, please check official GitHub repository for the latest instructions and updates.


Why this?

steem-js and dsteem libraries are not easy to integrate and in some cases are incompatible with some frameworks like Nativescript

NativeScript is an open-source framework to develop apps on the Apple iOS and Android platforms. It was originally conceived and developed by Progress. NativeScript apps are built using JavaScript, or by using any language that transpiles to JavaScript, such as TypeScript. - Wikipedia

This library is a solution to such cases when official libraries are not working. And also an alternative for just creating, signing, and broadcasting transactions.

How Steem-tx works:

I'm preparing another post about this library. A full instruction on how to serialize and sign Steem transactions with JavaScript. It will take a few days to be ready.

Installation

npm install steem-tx --save 

Usage

Create transaction:

const steemTx = require('steem-tx') 
const operations = [ 
  [ 
    'vote', 
    { 
      voter: 'guest123', 
      author: 'guest123', 
      permlink: '20191107t125713486z-post', 
      weight: 9900 
    } 
  ] 
] 
 
const tx = new steemTx.Transaction() 
tx.create(operations).then(() => console.log(tx.transaction)) 

Sign transaction:

(multi signature is supported)

// please use this key just for testing purposes 
const myKey = '5JRaypasxMx1L97ZUX7YuC5Psb5EAbF821kkAGtBj7xCJFQcbLg' 
const privateKey = steemTx.PrivateKey.from(myKey) 
 
tx.sign(privateKey) 
console.log(tx.signedTransaction) 

Broadcast transaction:

tx.broadcast().then(res => console.log(res)) 

Make node call:

steemTx.call('condenser_api.get_accounts', [['mahdiyari']]).then(res => console.log(res)) 

GitHub: https://github.com/mahdiyari/steem-tx-js npm package: https://www.npmjs.com/package/steem-tx


Feel free to test, use, share!

Future plans?

I'm building different applications mainly for Steem blockchain and I will try to keep this library as light as possible but also, useful with main functions for interacting with Steem blockchain. I believe having more tools will help grow use cases of Steem blockchain.

Many features, like getting posts and accounts are easy to implement with basic api calls. But serializing and signing transactions are a little bit complex to be implemented. That's why I decided to prepare another post about it and explain as much as I can.

Let's hope and work for a better future for the people in the World and on the Steem blockchain ❤

And remember, you can vote for mahdiyari as a witness