Commit 422d2d91 authored by Marius Momeu's avatar Marius Momeu

Add BCDB demo implemented in nodejs

parent 734e1cac
......@@ -61,6 +61,17 @@
A demo NodeJS script has been provided in `demos/ipfs-nodejs` that creates a file on the local FS, adds it into IPFS using the http gateway provided by the IPFS docker container and then tries to get the same file from IPFS and print its contents. In order to be able to run the script, you need to install the IPFS NodeJS client first:
npm install ipfs-http-client
In order to run the demo, execute the following:
cd demos/ipfs-nodejs
node demo.js
# BigchainDB
......@@ -74,3 +85,39 @@
Go through the following tutorial to better understand the arguments of the `` script:
A demo NodeJS script has been provided in `demos/bcdb-nodejs` that instantiates a new BCDB mnemonic and creates a transaction with an asset and metadata using the API port bound to the BCDB docker container. In order to be able to run the script, you need to install the BCDB NodeJS driver first:
npm install bigchaindb-driver
In order to run the demo, execute the following (if errors, look at the **NOTE** below):
cd demos/bcdb-nodejs
node demo.js
**NOTE** If you get an error similar to:
if (!Buffer.isBuffer(source)) throw new TypeError('Expected Buffer')
TypeError: Expected Buffer
at Object.encode (<path_to_node_modules>/node_modules/base-x/index.js:29:41)
at new Ed25519Keypair (<path_to_node_modules>/bigchaindb-driver/dist/node/Ed25519Keypair.js:28:33)
at Object.<anonymous> (<path_to_blockchain_dev_env>/demos/bcdb-nodejs/demo.js:7:15)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Function.Module.runMain (module.js:694:10)
at startup (bootstrap_node.js:204:16)
Then you need to edit `<path_to_node_modules>/bigchaindb-driver/dist/node/Ed25519Keypair.js` and add the following:
this.publicKey = _bs2.default.encode(Buffer.from(keyPair.publicKey));
this.privateKey = _bs2.default.encode(Buffer.from(keyPair.secretKey.slice(0, 32)));
const driver = require('bigchaindb-driver')
// BigchainDB server instance (e.g.
const API_PATH = 'http://localhost:9984/api/v1/'
// Create a new keypair.
const alice = new driver.Ed25519Keypair()
// Construct a transaction payload
const tx = driver.Transaction.makeCreateTransaction(
// Define the asset to store, in this example it is the current temperature
// (in Celsius) for the city of Berlin.
{ city: 'Berlin, DE', temperature: 22, datetime: new Date().toString() },
// Metadata contains information about the transaction itself
// (can be `null` if not needed)
{ what: 'My first BigchainDB transaction' },
// A transaction needs an output
[ driver.Transaction.makeOutput(
// Sign the transaction with private keys
const txSigned = driver.Transaction.signTransaction(tx, alice.privateKey)
// Send the transaction off to BigchainDB
const conn = new driver.Connection(API_PATH)
.then(retrievedTx => console.log('Transaction',, 'successfully posted.'))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment