-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
01deae7
commit 87f3694
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
examples/basic-usage-boilerplate/src/basic-usage-async-await.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const driver = require('bigchaindb-driver') | ||
|
||
|
||
// ======== Preparation ======== // | ||
const conn = new driver.Connection('https://test.bigchaindb.com/api/v1/', { | ||
app_id: 'c17a9968', | ||
app_key: '0b277b94893e7b0a5b4e6afd6bccb01d' | ||
}) | ||
|
||
const alice = new driver.Ed25519Keypair() | ||
const bob = new driver.Ed25519Keypair() | ||
|
||
const assetdata = { | ||
'bicycle': { | ||
'serial_number': 'abcd1234', | ||
'manufacturer': 'Bicycle Inc.', | ||
} | ||
} | ||
|
||
const metadata = { 'planet': 'earth' } | ||
|
||
|
||
// Call async basic usage function | ||
basicUsage() | ||
|
||
|
||
async function basicUsage() { | ||
// ======== Create Transaction Bicycle ======== // | ||
const txCreateAliceSimple = driver.Transaction.makeCreateTransaction( | ||
assetdata, | ||
metadata, | ||
[ | ||
driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(alice.publicKey)) | ||
], | ||
alice.publicKey | ||
) | ||
|
||
const txCreateAliceSimpleSigned = | ||
driver.Transaction.signTransaction(txCreateAliceSimple, alice.privateKey) | ||
|
||
|
||
// ======== Post Transaction and Fetch Result ======== // | ||
await conn.postTransaction(txCreateAliceSimpleSigned) | ||
await conn.pollStatusAndFetchTransaction(txCreateAliceSimpleSigned.id) | ||
|
||
const txTransferBob = driver.Transaction.makeTransferTransaction( | ||
[{ tx: txCreateAliceSimpleSigned, output_index: 0 }], | ||
[driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(bob.publicKey))], | ||
{ price: '100 euro' } | ||
) | ||
|
||
const txTransferBobSigned = driver.Transaction.signTransaction(txTransferBob, alice.privateKey) | ||
|
||
await conn.postTransaction(txTransferBobSigned) | ||
await conn.pollStatusAndFetchTransaction(txTransferBobSigned.id) | ||
|
||
|
||
// ======== Querying Assets ======== // | ||
const assets = await conn.searchAssets('Bicycle Inc.') | ||
console.log(assets) // eslint-disable-line no-console | ||
} |