1

I'm trying different ways to query my own bitcoind node on testnet but I'm failing every time.

Tried using bitcore's API and nodejs:

async function tryBitcoin() {
    const data = await axios.get('http://127.0.0.1:8333/api/BTC/testnet/address/mubUbyPazdyvhPJYPGWUkFWj7bkw1Yq8ys/balance');
    console.log('data: ', data);
}
tryBitcoin();

..but I'm getting this error:

Error: socket hang up
    at connResetException (node:internal/errors:683:14)
    at Socket.socketOnEnd (node:_http_client:471:23)

Tried with bitcoin-core and I get the same error from above:

async function tryBitcoinCore() {
    const Client = require('bitcoin-core');
    const client = new Client({ 
    network: 'testnet', 
    username: xxxxx, 
    password: zzzzz, 
    port: 8333 
    });

    const data = await client.getBlockchainInfo();
    console.log('data: ', data);
}
tryBitcoinCore();

And using curl:

curl --user xxxxx:zzzzzz -v 127.0.0.1:8333/api/BTC/testnet/address/mubUbyPazdyvhPJYPGWUkFWj7bkw1Yq8ys/balance

...gets an empty reply from the server:

*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8333 (#0)
* Server auth using Basic with user 'xxxxx'
> GET /api/BTC/testnet/address/mubUbyPazdyvhPJYPGWUkFWj7bkw1Yq8ys/balance HTTP/1.1
> Host: 127.0.0.1:8333
> Authorization: Basic zzzzzz=
> User-Agent: curl/7.64.1
> Accept: */*
> 
* Empty reply from server
* Connection #0 to host 127.0.0.1 left intact
curl: (52) Empty reply from server
* Closing connection 0

This is my bitcoin.conf file:

testnet=1
daemon=0
server=1
rpcuser=xxxxx
rpcpassword=zzzzz

zmqpubrawblock=tcp://127.0.0.1:29000
zmqpubrawtx=tcp://127.0.0.1:29000
zmqpubhashtx=tcp://127.0.0.1:29000
zmqpubhashblock=tcp://127.0.0.1:29000

prune=10000

listen=1

onion=127.0.0.1:9050
listenonion=1
onlynet=onion
proxy=127.0.0.1:9050
proxyrandomize=1

fallbackfee=0.0003

[test]
bind=127.0.0.1:8333

Any help here would be very much appreciated. Thanks!

5
  • Bitcoin Core and bitcore are two independent and unrelated pieces of software. You're trying to query Bitcoin Core using a bitcore API. Dec 29, 2021 at 21:45
  • Thanks! What package would I need then to query my own Bitcoin Core node through nodejs? @PieterWuille
    – dNyrM
    Dec 29, 2021 at 23:02
  • According to this article, I should be able to use the bitcoin-core npm package to query my Bitcoin Core node using nodejs but I get the same error that of using bitcore en.bitcoin.it/wiki/API_reference_(JSON-RPC)#Node.js @PieterWuille
    – dNyrM
    Dec 29, 2021 at 23:04
  • You're running a testnet node; its RPC interface by default is on port 18332. The bind=... only changes what port it listens for other node's connections for, not RPC (use rpcport= for that, but really, there is no need to change it). Dec 29, 2021 at 23:37
  • Awesome, man! It worked perfectly. Thanks a lot. If you want, you can leave an official answer with this comment and I can choose it as the correct one so you get the points. @PieterWuille
    – dNyrM
    Dec 30, 2021 at 7:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.