Create transaction (NodeJS)

Install NodeJS and npm

Create a new folder 'test'

mkdir test
cd ./test
npm install bloqly

Create file test-api.js

const bloqly = require('bloqly');

const PRIVATE_KEY = 'x9oZ6jrUVEBDP5C0005fPseqPwLshQbb9io7Upg8sNM=';

const NODE_URL = 'http://localhost:8082';

const SPACE = 'space1';

const KEY = 'test-key1';

async function createTransaction() {
    let lastId = await bloqly.getLastId(NODE_URL, SPACE, KEY);

    const nonce = lastId.nonce + 1;

    let signedTransaction = bloqly.signTransaction(
        PRIVATE_KEY,
        SPACE,
        KEY,
        nonce,
        Date.now(),
        'test',
        'memo',
        ['tag1', 'tag2']
    );
    
    console.log(signedTransaction)

    const encodedTransaction = bloqly.encodeTransaction(signedTransaction);

    const res = await bloqly.sendSignedTransaction(NODE_URL, encodedTransaction);

    console.log(res)
}

createTransaction().then(() => console.log('done'));

Run script

Expected result:

Now lets check transaction is created and saved in blockchain

Will print the created transaction details

Last updated

Was this helpful?