I am running the golang implementation of bitcoin and trying to query the JSON-RPC API remotely. I am trying with the example demonstrated
here but I get an error saying the connection was refused.
I have configured rpcuser and rpcpass in both btcd.conf and btcctl.conf, I have also tried generating new key and cert with the gencerts command
gencerts -d /home/user/.certsforhosts/ -H 192.168.0.104
but I still get the same error.
What might be wrong with my configuration?
btcd.conf
datadir=/home/user/blockchain/
rpcuser=user1
rpcpass=pass1
rpclimituser=user2
rpclimitpass=pass2
txindex=1
addrindex=1
rpccert=/home/user/.certsforhosts/rpc.cert
rpckey=/home/user/.certsforhosts/rpc.key
btcctl.conf
rpcuser=user1
rpcpass=pass1
rpccert=/home/user/.certsforhosts/rpc.cert
my code
var fs = require('fs');
var WebSocket = require('ws');
var cert = fs.readFileSync('path/to/my/rpc.cert');
var user = "user1";
var password = "pass1";
var ws = new WebSocket('wss://192.168.0.102:8334/ws', {
headers: {
'Authorization': 'Basic '+Buffer.from(user+':'+password).toString('base64')
},
cert: cert,
ca: [cert]
});
ws.on('open', function() {
console.log('CONNECTED');
ws.send('{"jsonrpc":"1.0","id":"0","method":"notifyblocks","params":[]}');
});
ws.on('message', function(data, flags) {
console.log(data);
});
ws.on('error', function(derp) {
console.log('ERROR:' + derp);
})
ws.on('close', function(data) {
console.log('DISCONNECTED');
})