Whether you're just getting started with Hive or you're building tools for power users, this post gives you four essential Node.js scripts to make your journey smoother. From signing custom_json operations and transferring tokens, to reviewing account history and checking RC status, these snippets are your gateway into real-time blockchain interactions.
If you're ready to level up your Web3 development skills, these scripts are a great place to start. Let's get coding! 👨‍💻🚀
Sign a Custom JSON Operation
Useful for apps that store user actions on-chain (e.g., polls, games, NFTs):
const json = JSON.stringify({ action: 'like', target: 'hive-123456' });
const op = [
'custom_json',
{
required_auths: [],
required_posting_auths: ['your_username'],
id: 'your_app_id',
json,
},
];
client.broadcast.sendOperations([op], postingKey).then(console.log).catch(console.error);
Transfer HIVE or HBD
Automate token transfers—great for tipping bots or faucets:
const transfer = [
'transfer',
{
from: 'your_username',
to: 'receiver_username',
amount: '1.000 HIVE',
memo: 'Thanks for your post!',
},
];
client.broadcast.sendOperations([transfer], activeKey).then(console.log).catch(console.error);
Fetch Transaction History (Virtual Operations too)
Track votes, rewards, or transfers from account history:
client.call('condenser_api', 'get_account_history', ['your_username', -1, 100]).then(history => {
history.forEach(([index, op]) => console.log(op.op));
});
Check RC (Resource Credits) Availability
To ensure users have enough bandwidth to transact:
client.rc.findRCAccounts(['your_username']).then(res => {
const rc = res.rc_accounts[0];
console.log('RC:', rc.rc_manabar.current_mana);
});
Posted using The BBH Project