<p>I'm trying different ways to query my own bitcoind node on testnet but I'm failing every time.</p>
<p>Tried using <a href="https://github.com/bitpay/bitcore/blob/master/packages/bitcore-node/docs/api-documentation.md#get-balance-for-an-address" rel="nofollow noreferrer">bitcore's</a> API and nodejs:</p>
<pre><code>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();
</code></pre>
<p>..but I'm getting this error:</p>
<pre><code>Error: socket hang up
    at connResetException (node:internal/errors:683:14)
    at Socket.socketOnEnd (node:_http_client:471:23)
</code></pre>
<p>Tried with <a href="https://en.bitcoin.it/wiki/API_reference_(JSON-RPC)#Node.js" rel="nofollow noreferrer">bitcoin-core</a> and I get the same error from above:</p>
<pre><code>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();
</code></pre>
<p>And using <code>curl</code>:</p>
<pre><code>curl --user xxxxx:zzzzzz -v 127.0.0.1:8333/api/BTC/testnet/address/mubUbyPazdyvhPJYPGWUkFWj7bkw1Yq8ys/balance
</code></pre>
<p>...gets an empty reply from the server:</p>
<pre><code>*   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'
&gt; GET /api/BTC/testnet/address/mubUbyPazdyvhPJYPGWUkFWj7bkw1Yq8ys/balance HTTP/1.1
&gt; Host: 127.0.0.1:8333
&gt; Authorization: Basic zzzzzz=
&gt; User-Agent: curl/7.64.1
&gt; Accept: */*
&gt; 
* Empty reply from server
* Connection #0 to host 127.0.0.1 left intact
curl: (52) Empty reply from server
* Closing connection 0
</code></pre>
<p>This is my <code>bitcoin.conf</code> file:</p>
<pre><code>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
</code></pre>
<p>Any help here would be very much appreciated. Thanks!</p>

CC BY-SA 4.0
2021-12-29T21:45:00.223Z
Bitcoin Core and bitcore are two independent and unrelated pieces of software. You're trying to query Bitcoin Core using a bitcore API.
Pieter Wuille
CC BY-SA 4.0
2021-12-29T23:02:13.793Z
Thanks! What package would I need then to query my own Bitcoin Core node through nodejs? @PieterWuille
dNyrM
CC BY-SA 4.0
2021-12-29T23:04:39.163Z
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 https://en.bitcoin.it/wiki/API_reference_(JSON-RPC)#Node.js @PieterWuille
dNyrM
CC BY-SA 4.0
2021-12-29T23:37:22.490Z
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).
Pieter Wuille
CC BY-SA 4.0
2021-12-30T07:26:06.153Z
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
<bitcoin-core><bitcoind><api><full-node><node.js>
Can't query own node
dNyrM
# Can't query own node

(Asked by: username_0 on 2021-12-29)

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!

**Tags:** bitcoin-core, bitcoind, api, full-node, node.js

> **Comments:**
> **username_1**: Bitcoin Core and bitcore are two independent and unrelated pieces of software. You're trying to query Bitcoin Core using a bitcore API.  
> **username_0**: Thanks! What package would I need then to query my own Bitcoin Core node through nodejs? @PieterWuille  
> **username_0**: 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 https://en.bitcoin.it/wiki/API_reference_(JSON-RPC)#Node.js @PieterWuille  
> **username_1**: 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).  
> **username_0**: 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  

---

## 0 answers

