Author

Topic: BTCD node.js ERROR:Error: connect ECONNREFUSED (Read 207 times)

sr. member
Activity: 490
Merit: 389
Do not trust the government
September 17, 2018, 11:18:23 AM
#7
Maybe is a firewall problem, did you open the bitcoin port on your firewall? Remember you can do it manually with the firewall application or you can do it by command line with the next command:

Code:
firewall-cmd --permanent --zone=public --add-port=8334/tcp

Try to fix it this way and if the problem persist, let us know.

I assume, sir, that you were too busy and haven't followed up on the posts.
The problem was solved. He was binding only to localhost which made connections over LAN impossible.

You were right! It was only listening on the localhost 127.0.0.1, thank you very much!

You are welcome, my child.
legendary
Activity: 3346
Merit: 3125
September 17, 2018, 11:01:02 AM
#6
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
Code:
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
Code:
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
Code:
rpcuser=user1
rpcpass=pass1
rpccert=/home/user/.certsforhosts/rpc.cert

my code
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');
})

Maybe is a firewall problem, did you open the bitcoin port on your firewall? Remember you can do it manually with the firewall application or you can do it by command line with the next command:

Code:
firewall-cmd --permanent --zone=public --add-port=8334/tcp

Try to fix it this way and if the problem persist, let us know.

newbie
Activity: 11
Merit: 5
September 17, 2018, 08:18:48 AM
#5
You were right! It was only listening on the localhost 127.0.0.1, thank you very much!

For future reference:
I binded an IP address on my router to the MAC of my device the RPC is running on and used that IP with rpclisten option on btcd.conf, like this:

rpclisten=192.168.0.102
rpclisten=192.168.0.102:8334

My code now works and with getblockcount method I got the value I was expecting to see, the same as running btcctl getblockcount locally.
sr. member
Activity: 490
Merit: 389
Do not trust the government
September 17, 2018, 07:53:42 AM
#4
Thank you for your reply, the default rpc port on btcd is 8334 and I haven't changed that.
On netstat I can see that btcd is listening on that port.

I would really suggest you check from the computer that you are connecting from.
You can use "nc -v 192.168.0.104 8334". (I assume that 192.168.0.104 is the IP of the host with rpc)

It is good that the program is listening on that port, but it might bind only to localhost IP address (eg. 127.0.0.1) and not to the address accessible by your other PC. Best practice is to simply check from the PC making a connection. It can rule out any firewall problems as well.
newbie
Activity: 11
Merit: 5
September 17, 2018, 07:20:53 AM
#3
Thank you for your reply, the default rpc port on btcd is 8334 and I haven't changed that.
On netstat I can see that btcd is listening on that port.
sr. member
Activity: 490
Merit: 389
Do not trust the government
September 17, 2018, 06:47:18 AM
#2
I am not familiar with these implementations, but you should check if rpc is binding to the right address.

Check if the right port is open from the PC that you are connecting from. You can check with nmap or netcat.
newbie
Activity: 11
Merit: 5
September 16, 2018, 01:49:06 PM
#1
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
Code:
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
Code:
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
Code:
rpcuser=user1
rpcpass=pass1
rpccert=/home/user/.certsforhosts/rpc.cert

my code
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');
})
Jump to: