morphit/node_modules/@beblurt/dblurt/guide/getting-started.md

1.9 KiB

Getting started with dblurt

This guide gets a Node.js project connected to Blurt in a few minutes.

1. Install

npm install @beblurt/dblurt

@beblurt/dblurt declares its Node.js runtime requirement in package.json; see runtime-compatibility.md for the current contract.

2. Create a client

const { Client } = require('@beblurt/dblurt');

const rpcList = [
    'https://rpc.blurt.blog',
    'https://blurt-rpc.saboin.com',
    'https://rpc.beblurt.com',
    'https://blurtrpc.dagobert.uk',
    'https://rpc.drakernoise.com'
];

const client = new Client(rpcList, {
    timeout: 15_000,
    failoverThreshold: 3
});

The endpoint list is used by the built-in failover system. See failover.md.

3. Read chain properties

async function main() {
    const props = await client.condenser.getDynamicGlobalProperties();
    console.log({
        head: props.head_block_number,
        irreversible: props.last_irreversible_block_num,
        time: props.time
    });
}

main().catch(console.error);

4. Load an account

const accounts = await client.condenser.getAccounts(['beblurt']);
const account = accounts[0];

if (account) {
    console.log(account.name);
    console.log(account.balance);
    console.log(account.vesting_shares);
}

5. Query social data through Nexus Layer 2

const posts = await client.nexus.getRankedPosts('trending', null, null, 10, 'blurt');

for (const post of posts) {
    console.log(`${post.author}/${post.permlink}: ${post.title}`);
}

For the Layer 1 / Nexus distinction, see Blockchain model.

6. Where to go next