Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'bigchaindb-driver' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
{
app_id: '',
app_key: ''
}
);
//asd
bdbOrm.define("crabModel", "https://schema.org/v1/crab")
// define(,)
// : represents the name of model you want to store
// : any information you want to pass about the model (can be string or object)
// note: cannot be changed once set!
bdbOrm.define("classic_car_asset", "http://127.0.0.1:9984/api/v1/classic_car_asset")
// create a public and private key for Alice and Bob
const aliceKeypair = new driver.Ed25519Keypair()
// CREATE ASSET
// from the defined models in our bdbOrm we create an asset with Alice as owner
bdbOrm.models.classic_car_asset.create({
keypair: aliceKeypair,
data: { serial_code: 'n0tp01ntAt0p01ntB',
manufacturer: 'classik',
transmission: 'manual',
drivetrain: 'RWD' }
})
.then(asset => {
/*
asset is an object with all our data and functions
asset.id equals the id of the asset
asset.data is data of the last (unspent) transaction
asset.transactionHistory gives the full raw transaction history
const assetdata = {
'bicycle': {
'serial_number': 'abcd1234',
'manufacturer': 'Bicycle Inc.',
}
}
const metadata = { 'planet': 'earth' }
// ======== 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 ======== //
conn.postTransactionCommit(txCreateAliceSimpleSigned)
// ======== Transfer Bicycle to Bob ======== //
.then((fetchedTx) => {
const txTransferBob = driver.Transaction.makeTransferTransaction(
[{ tx: fetchedTx, output_index: 0 }],
[driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(bob.publicKey))],
{ price: '100 euro' }
)
createTransaction(publicKey, privateKey, payload, metadata) {
try {
// Create a transation
const tx = driver.Transaction.makeCreateTransaction(
payload,
metadata,
[
driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(publicKey))
],
publicKey
)
// sign/fulfill the transaction
const txSigned = driver.Transaction.signTransaction(tx, privateKey)
return this.conn.postTransactionCommit(txSigned).then(() => txSigned)
} catch (error) {
return Promise.reject(error)
}
}
function sendToBigchainDB(asset, keypair, count, nTx) {
const txSimpleAsset = BigchainDB.Transaction.makeCreateTransaction(
asset,
{
'metadata': 'sdfs'
},
// counterparty is the owner
[BigchainDB.Transaction.makeOutput(
BigchainDB.Transaction.makeEd25519Condition(keypair.publicKey))],
keypair.publicKey
)
// Sign the transaction with private keys
const txSigned = BigchainDB.Transaction.signTransaction(txSimpleAsset, keypair.privateKey)
// console.log(txSigned.id)
// console.log(sizeof(txSigned))
//console.log(JSON.stringify(txSigned))
function sendToBigchainDB(asset, keypair, count, nTx) {
const txSimpleAsset = BigchainDB.Transaction.makeCreateTransaction(
asset,
{
'metadata': 'sdfs'
},
// counterparty is the owner
[BigchainDB.Transaction.makeOutput(
BigchainDB.Transaction.makeEd25519Condition(keypair.publicKey))],
keypair.publicKey
)
// Sign the transaction with private keys
const txSigned = BigchainDB.Transaction.signTransaction(txSimpleAsset, keypair.privateKey)
// console.log(txSigned.id)
// console.log(sizeof(txSigned))
//console.log(JSON.stringify(txSigned))
conn.postTransaction(txSigned)
}
transferTransaction(tx, fromPublicKey, fromPrivateKey, toPublicKey, metadata) {
try {
const txTransfer = driver.Transaction.makeTransferTransaction(
[{ 'tx': tx, 'output_index': 0 }],
[driver.Transaction.makeOutput(driver.Transaction.makeEd25519Condition(toPublicKey))],
metadata,
)
const txTransferSigned = driver.Transaction.signTransaction(txTransfer, fromPrivateKey)
// send it off to BigchainDB
return this.conn.postTransactionCommit(txTransferSigned).then(() => txTransferSigned)
} catch (error) {
return Promise.reject(error)
}
}
async function sendToBigchainDB(asset, keypair) {
const txSimpleAsset = BigchainDB.Transaction.makeCreateTransaction(
asset,
{
'metadata': 'sdfs'
},
// counterparty is the owner
[BigchainDB.Transaction.makeOutput(
BigchainDB.Transaction.makeEd25519Condition(keypair.publicKey))],
keypair.publicKey
)
// Sign the transaction with private keys
const txSigned = BigchainDB.Transaction.signTransaction(txSimpleAsset, keypair.privateKey)
console.log('txSigned ', txSigned.id)
console.log('sizeof ', sizeof(txSigned))
//console.log(JSON.stringify(txSigned))
conn.postTransaction(txSigned)
}
function sendToBigchainDB(asset, keypair, count, nTx) {
const txSimpleAsset = BigchainDB.Transaction.makeCreateTransaction(
asset,
{
'metadata': 'sdfs'
},
// counterparty is the owner
[BigchainDB.Transaction.makeOutput(
BigchainDB.Transaction.makeEd25519Condition(keypair.publicKey))],
keypair.publicKey
)
// Sign the transaction with private keys
const txSigned = BigchainDB.Transaction.signTransaction(txSimpleAsset, keypair.privateKey)
// console.log(txSigned.id)
// console.log(sizeof(txSigned))
//console.log(JSON.stringify(txSigned))
conn.postTransaction(txSigned)
}
var BigchainDB = require('bigchaindb-driver')
var bip39 = require('bip39')
// ***************************************************************
// Simple example:
const alice = new BigchainDB.Ed25519Keypair()
const bob = new BigchainDB.Ed25519Keypair()
console.log(alice)
const API_PATH = 'http://127.0.0.1:9984/api/v1/'
const conn = new BigchainDB.Connection(API_PATH, {
app_id: '',
app_key: ''
})
// copy to file
const enemy = new BigchainDB.Ed25519Keypair(bip39.mnemonicToSeed('seedPhrase').slice(0, 32))
createAssets()
async function createAssets() {
const enemyAsset = await createEnemy(enemy)
// Transfer transaction
const conn = new BigchainDB.Connection(API_PATH, {
app_id: '',
app_key: ''
})
// const API_PATH = 'https://test-venus.ipdb.io/api/v1/'
// const conn = new BigchainDB.Connection(API_PATH, {
// 'X-Secret-Access-Token': 'secret-venus'
// })
const user = new BigchainDB.Ed25519Keypair(bip39.mnemonicToSeed('seedPhrase').slice(0, 32))
console.log('user', user);
console.log('conn', conn)
// Execute ever x seconds: '*/15 * * * * *'
let count = 0
const numTransactions = 20
var j = schedule.scheduleJob('*/1 * * * * *', function () {
const ua = postTransactions(numTransactions)
count++
console.log(count)