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!
bind=...
only changes what port it listens for other node's connections for, not RPC (userpcport=
for that, but really, there is no need to change it).