How to use bigchaindb-driver - 10 common examples

To help you get started, we’ve selected a few bigchaindb-driver examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bigchaindb / project-jannowitz / js-examples / test-orm.js View on Github external
{
      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
github bigchaindb / js-bigchaindb-driver / examples / src / basic-usage.js View on Github external
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' }
        )
github bigchaindb / js-driver-orm / src / connection.js View on Github external
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)
        }
    }
github bigchaindb / project-jannowitz / js-examples / transactionsPerSecond.js View on Github external
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))
github bigchaindb / project-jannowitz / js-examples / transactionsPerSecond.js View on Github external
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)
}
github bigchaindb / js-driver-orm / src / connection.js View on Github external
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)
        }
    }
github bigchaindb / project-jannowitz / js-examples / differentPayloadSize.js View on Github external
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)
}
github bigchaindb / project-jannowitz / js-examples / transactionsPerSecond.js View on Github external
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)
}
github bigchaindb / project-jannowitz / js-examples / create_transfer.js View on Github external
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
github bigchaindb / project-jannowitz / js-examples / issue2226.js View on Github external
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)

bigchaindb-driver

Node.js driver for BigchainDB

Apache-2.0
Latest version published 3 years ago

Package Health Score

57 / 100
Full package analysis