diff --git a/docs/source/usage.rst b/docs/source/usage.rst index b16d3b5..27248e6 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -357,6 +357,134 @@ Recap: Asset Creation & Transfer .then(() => conn.searchAssets('Bicycle Inc.')) .then(assets => console.log('Found assets with serial number Bicycle Inc.:', assets)) + +Websocket Event Stream API Usage +-------------------------------- + +The Event Stream API enables new ways to interact with BigchainDB, making it possible for your application to subscribe to all newly–confirmed transactions that are happening in the system. +Below piece of code can be opened in your web browser. It will connect to your websocket (change it at ``var wsUri``). This web page will display all validated transactions. + +.. code-block:: html + + + + WebSocket BigchainDB + + + + + + + + + + + + + + +
+

WebSocket API Stream Valid Transactions BigchainDB

+ + +
+ + +
+
+ + +Besides that, a NodeJs version has been created to display the validated transactions. +All transactions are printed to the console. To use this piece of code, you will need the ``ws`` (WebSocket package) through npm: ``npm install --save ws``. + +.. code-block:: js + + const WebSocket = require('ws') + + const ws = new WebSocket('ws://localhost:9985/api/v1/streams/valid_transactions') + + ws.on('open', () => { + console.log("CONNECTED") + }); + + ws.on('message', (data) => { + let json = JSON.parse(data) + console.log("\nTransactionId: ", json.transaction_id) + console.log("AssetId: ", json.asset_id) + console.log("BlockId: ", json.block_id) + }); + + Difference unspent and spent output ----------------------------------- An unspent output is simply an output of a transaction which isn't yet an input of another transaction.