Question:

how to get block information using node js

Isabella: 5 weeks ago

I have used bitcoin-core package in node js to get the information about the block detail using rpc command.

For example:

var Client = require('bitcoin-core');

const client = new Client({ headers:'false', host:'127.0.0.1', network:'testnet', password:'xxxx',port:'18332', ssl: {
    enabled: false,
    strict: false
  }, timeout:'3000', username:'xxxx' });

client.getBlockchainInformation().then((help) => console.log(help));

It throws below mentioned error:

unhandled rejection rpcerror: not found

Any solution for this.

Thanks in advance.

Answer:
Ava: 5 weeks ago

The function client.getBlockchainInformation and the other methods exposed by the bitcoin-core npm module use bitcoin-core's REST interface. (https://github.com/bitcoin/bitcoin/blob/master/doc/REST-interface.md) In order to use it, however, it must be enabled when you start bitcoind with the -rest flag.

The REST API can be enabled with the -rest option.

The interface runs on the same port as the JSON-RPC interface, by default port 8332 for mainnet, port 18332 for testnet, and port 18443 for regtest.

e.g.:

$ bitcoind -rest

or in bitcoin.conf

rest=1