how to get block information using node js

1

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.

Sarath Kumar

Posted 2018-09-13T05:38:30.420

Reputation: 23

That code is trying to connect to a bitcoin testnet node RPC running locally (127.0.0.1 port 18332). Do you have one running locally?JBaczuk 2018-09-13T14:49:26.767

Yes I have one running locally.Sarath Kumar 2018-09-14T02:27:34.190

Answers

1

The function client.getBlockchainInformation and the other methods exposed by the bitcoin-core npm module use bitcoin-core's REST interface. 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

JBaczuk

Posted 2018-09-13T05:38:30.420

Reputation: 6 172

Can you please suggest me how tether node is setup like a bitcoin.Sarath Kumar 2018-09-14T03:51:21.450

If it is unrelated to this post, please create a new question.JBaczuk 2018-09-14T04:02:46.153