How to use the bigchaindb-driver.Transaction function in bigchaindb-driver

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

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 / crypto-conditions.js View on Github external
async function transfer(txSigned) {

    let createTranfer = BigchainDB.Transaction.makeTransferTransaction(
      [{ tx: txSigned,
        output_index: 0
     }],
      [BigchainDB.Transaction.makeOutput(
            BigchainDB.Transaction.makeEd25519Condition(receiver.publicKey))],
      {
          what: "Transfer transaction"
      }
    );

    const serializedTransaction = BigchainDB.Transaction.serializeTransactionIntoCanonicalString(createTranfer)
    // at the input of the spending transaction
    let fulfillment1 = BigchainDB.Transaction.makeEd25519Condition(user1.publicKey, false)
    const transactionUniqueFulfillment1 = createTranfer.inputs[0].fulfills ? serializedTransaction
                .concat(createTranfer.inputs[0].fulfills.transaction_id)
                .concat(createTranfer.inputs[0].fulfills.output_index) : serializedTransaction
    const transactionHash1 = sha256Hash(transactionUniqueFulfillment1)
    fulfillment1.sign(Buffer.from(transactionHash1, 'hex'), new Buffer.from(base58.decode(user1.privateKey)))

    
    let fulfillment2 = BigchainDB.Transaction.makeEd25519Condition(user2.publicKey, false)
    const transactionUniqueFulfillment2 = createTranfer.inputs[0].fulfills ? serializedTransaction
                .concat(createTranfer.inputs[0].fulfills.transaction_id)
                .concat(createTranfer.inputs[0].fulfills.output_index) : serializedTransaction
    const transactionHash2 = sha256Hash(transactionUniqueFulfillment2)
    fulfillment2.sign(Buffer.from(transactionHash2, 'hex'), new Buffer.from(base58.decode(user2.privateKey)))

    // 2 out of 3 need to sign the fulfillment. Still condition3 is needed as the "circuit definition" is needed.
    // See https://github.com/bigchaindb/cryptoconditions/issues/94
github gautamdhameja / bigchaindb-tcr / src / shared / bdb.js View on Github external
if (outputs.length > 0) {
        for (const output of outputs) {
            let condition = driver.Transaction.makeEd25519Condition(output.publicKey)
            let transferOutput
            if (output.amount > 0) {
                transferOutput = driver.Transaction.makeOutput(condition, output.amount.toString())
            } else {
                transferOutput = driver.Transaction.makeOutput(condition)
            }

            transferOutput.public_keys = [output.publicKey]
            transferOutputs.push(transferOutput)
        }
    }

    const txTransfer = driver.Transaction.makeTransferTransaction(
        unspentTxs,
        transferOutputs,
        metadata
    )

    const txSigned = driver.Transaction.signTransaction(txTransfer, keypair.privateKey)
    return await conn.postTransactionCommit(txSigned)
}
github bigchaindb / project-jannowitz / rbac / demo / src / rbac.js View on Github external
async function createNewAsset(keypair, asset, metadata) {

    let condition = driver.Transaction.makeEd25519Condition(keypair.publicKey, true)

    let output = driver.Transaction.makeOutput(condition)
    output.public_keys = [keypair.publicKey]

    const transaction = driver.Transaction.makeCreateTransaction(
        asset,
        metadata,
        [output],
        keypair.publicKey
    )

    const txSigned = driver.Transaction.signTransaction(transaction, keypair.privateKey)
    let tx
    await conn.postTransaction(txSigned)
        .then(() => conn.pollStatusAndFetchTransaction(txSigned.id))
        .then(retrievedTx => {
            tx = retrievedTx
        })

bigchaindb-driver

Node.js driver for BigchainDB

Apache-2.0
Latest version published 8 months ago

Package Health Score

68 / 100
Full package analysis