Added stream functions to Steem JS documentation

U5du4GjP1oJBeM1wwJnXtGAZmS4PZb1_1680x8400.png

For the longest time I have been polling the getAccountHistory() function every few seconds to watch for specific operations for an account until I recently discovered the "stream" functions included in the Steem JS library.

I never knew about the stream functions before because they are annoyingly not included in the documentation! So I decided I should fix that so others have an easier time than I did. Additionally, most of the current documentation merely shows what the methods are, but doesn't provide any other information about what the parameters are, what the return values are, or anything else really.

So I have added the following documentation which is much more thorough and what I wish I had when first trying out the Steem JS library:

Stream Block Number

Streams block numbers by calling the callback function each time a new block is created.

var release = steem.api.streamBlockNumber(mode, function(err, result) {
    console.log(err, result);
});
// Call the returned 'release' function to stop streaming
release();

Parameters:

  • mode: 'head' (default) or 'irreversible'
  • callback: function to be called with the number of each new block that is created

Stream Block

Streams blocks by calling the callback function each time a new block is created.

steem.api.streamBlock(mode, function(err, result) {
    console.log(err, result);
});
// Call the returned 'release' function to stop streaming
release();

Parameters:

  • mode: 'head' (default) or 'irreversible'
  • callback: function to be called with the number of each new block that is created

Example block data passed as the "result" property to the callback function:

block_id: "01091c2ccea73ce2013017239cb8e9c6adac7a2a"
extensions: []
previous: "01091c2b769f7554a5932b29b81c3460fc6f335b"
signing_key: "STM6GcZkfF2rNWwNUmhDCmfLZTpdfMgQDAcAvvGL4MZ7iNVapAVkT"
timestamp: "2017-11-20T01:27:36"
transaction_ids: ["11d0ba9308dd3c25124753eb72ff95c984faf299", ...]
transaction_merkle_root: "4adfa63d8532427add4c081272af09443b8bc70d"
transactions: [{...}, ...]
witness: "pfunk"
witness_signature: "2018f9d65bf44ec3f79d5763ff4bda633146f4f3f4b8998939f648514da00c809a32f25f633b91a5610b49fd735df78cfb841576ce95133d2ee1c7a4e208dc376d"

Stream Transactions

Streams transactions by calling the callback function each time a new block is created with each transaction in the block.

steem.api.streamTransactions(mode, function(err, result) {
    console.log(err, result);
});
// Call the returned 'release' function to stop streaming
release();

Parameters:

  • mode: 'head' (default) or 'irreversible'
  • callback: function to be called with the number of each new block that is created

Example transaction data passed as the "result" property to the callback function:

expiration: "2017-11-20T01:33:06"
extensions: []
operations: [...]
ref_block_num: 7299
ref_block_prefix: 1091086591
signatures: ["205a04e6d6184bc18188938d86565505510cefac33b0838064578bf3395752edaa91c2f3e4485c8e3dd734c797c1ca2ee97"]

Stream Operations

Streams operations by calling the callback function each time a new block is created with each operation in each transaction in the block.

steem.api.streamOperations(mode, function(err, result) {
    console.log(err, result);
});
// Call the returned 'release' function to stop streaming
release();

Parameters:

  • mode: 'head' (default) or 'irreversible'
  • callback: function to be called with the number of each new block that is created

Example operation data passed as the "result" property to the callback function:

["vote", {...}]

You can see the pull request here: https://github.com/steemit/steem-js/pull/283



Posted on Utopian.io - Rewarding Open Source Contributors

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center