Skip to content

Instantly share code, notes, and snippets.

@pinheadmz
Created July 4, 2019 16:58
Show Gist options
  • Save pinheadmz/b3c15d104b94cd5f28aa6f81c9c55bea to your computer and use it in GitHub Desktop.
Save pinheadmz/b3c15d104b94cd5f28aa6f81c9c55bea to your computer and use it in GitHub Desktop.
'use strict';
const bcoin = require('bcoin');
const client = require('bclient');
const plugin = bcoin.wallet.plugin;
const network = bcoin.Network.get('regtest');
// create full node
const node = new bcoin.FullNode({
network: 'regtest',
memory: true,
indexTx: true
});
// add wallet to full node
node.use(plugin);
// create wallet API client
const walletClient = new client.WalletClient({
port: network.walletPort
});
// create node API client
const nodeClient = new client.NodeClient({
port: network.rpcPort
});
(async () => {
// open node
await node.open();
// create wallet
await walletClient.createWallet('test');
// get wallet address from default account
const addr = await walletClient.createAddress('test', 'default');
console.log(addr);
// generate 200 blocks to wallet address
const blocks = await nodeClient.execute(
'generatetoaddress',
[200, addr.address]
);
console.log(blocks);
// get block #150
const block150 = await nodeClient.getBlock(blocks[150]);
console.log(block150);
// get coinbase tx from block 150
const txHash = block150.txs[0].hash;
const tx = await nodeClient.getTX(txHash);
console.log(tx);
// close node
await node.close();
})().catch((err) => {
console.error(err.stack);
process.exit(1);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment