From f40d0b06ba26ff14554ca913993fdb63a556bc57 Mon Sep 17 00:00:00 2001 From: vrde Date: Fri, 23 Jun 2017 15:00:55 +0200 Subject: [PATCH] Simplify README.md and change example --- README.md | 78 +++++++++++++++++++++++++------------------------------ 1 file changed, 36 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index f61eeb4..87e944b 100644 --- a/README.md +++ b/README.md @@ -33,46 +33,40 @@ npm install bigchaindb-driver ### Example: Create a transaction ```js -import * as driver from 'bigchaindb-driver' +const driver = require('bigchaindb-driver') // BigchainDB server instance or IPDB (e.g. https://test.ipdb.io/api/v1/) const API_PATH = 'http://localhost:9984/api/v1/' -// Create a new user with a public-private key pair -// (or a whole bunch of them, nobody's counting) +// Create a new keypair. const alice = new driver.Ed25519Keypair() // Construct a transaction payload -// `driver.Transaction.makeCreateTransaction()`: create a new asset -// `driver.Transaction.makeTransferTransaction()`: transfer an existing asset const tx = driver.Transaction.makeCreateTransaction( - { assetMessage: 'My very own asset...' }, - { metaDataMessage: 'wrapped in a transaction' }, + // 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()`: requires a crypto-condition - // `driver.Transaction.makeEd25519Condition()`: simple public key output [ driver.Transaction.makeOutput( driver.Transaction.makeEd25519Condition(alice.publicKey)) ], alice.publicKey ) -// Optional: You've got everything you need, except for an asset -// and metadata. Maybe define them here, any JSON-serializable object -// will do - -// Ok, now that you have a transaction, you need to *sign* it -// cause, you know... cryptography and ¯\_(ツ)_/¯ - -// Sign/fulfill the transaction with private keys +// Sign the transaction with private keys const txSigned = driver.Transaction.signTransaction(tx, alice.privateKey) // Send the transaction off to BigchainDB -let conn = new driver.Connection(API_PATH) +const conn = new driver.Connection(API_PATH) conn.postTransaction(txSigned) - .then(() => conn.getStatus(txSigned.id)) - .then((res) => console.log('Transaction status:', res.status)) + .then(() => conn.pollStatusAndFetchTransaction(txSigned.id)) + .then(retrievedTx => console.log('Transaction', retrievedTx.id, 'successfully posted.')) ``` ## Use a pre-built image (browser only) @@ -82,54 +76,54 @@ conn.postTransaction(txSigned) - HTML5 boilerplate – all you really need… + BigchainDB boilerplate - - + -

Hello BigchainDB

+

Hello BigchainDB

+

Your transaction id is: processing

```