ruimarinho / bitcoin-core

A modern Bitcoin Core REST and RPC client.
477 stars 186 forks source link

Unhandled rejection Error: Extension "json" is not supported #88

Closed vincenzopalazzo closed 4 years ago

vincenzopalazzo commented 5 years ago

Hello,

I have the error when run this code:

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

const myNode = new Client({
    port: 8332,
    username: 'pippo',
    password: 'pippo',
    network: 'regtest'
});

//myNode.getBlockchainInfo().then((help) => console.log(help));

// Block header 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
 myNode.getBlockHeadersByHash("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
 { extension: 'exa' }).then((block) => console.log(block));

The error

Unhandled rejection Error: Extension "json" is not supported
    at _bluebird.default.try (/home/vincenzo/Desktop/ClienBlock/node_modules/bitcoin-core/dist/src/index.js:221:15)
    at tryCatcher (/home/vincenzo/Desktop/ClienBlock/node_modules/bluebird/js/release/util.js:16:23)
    at Function.Promise.attempt.Promise.try (/home/vincenzo/Desktop/ClienBlock/node_modules/bluebird/js/release/method.js:39:29)
    at Client.getBlockHeadersByHash (/home/vincenzo/Desktop/ClienBlock/node_modules/bitcoin-core/dist/src/index.js:219:33)
    at Object.<anonymous> (/home/vincenzo/Desktop/ClienBlock/js/server-bitcoin-core.js:13:9)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3
pedrobranco commented 5 years ago

As the example provided here you must pass the second argument count, and the extension option is hex, not exa:

const headers = await client.getBlockHeadersByHash(
  '0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206', // txid
  1, // count
  { extension: 'hex' } // options
);