Bitcoin Forum
October 15, 2018, 08:53:41 PM *
News: Make sure you are not using versions of Bitcoin Core other than 0.17.0 [Torrent], 0.16.3, 0.15.2, or 0.14.3. More info.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: BTCD node.js ERROR:Error: connect ECONNREFUSED  (Read 52 times)
GodlyWizard
Newbie
*
Offline Offline

Activity: 11
Merit: 4


View Profile
September 16, 2018, 06: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');
})
1539636821
Hero Member
*
Offline Offline

Posts: 1539636821

View Profile Personal Message (Offline)

Ignore
1539636821
Reply with quote  #2

1539636821
Report to moderator
1539636821
Hero Member
*
Offline Offline

Posts: 1539636821

View Profile Personal Message (Offline)

Ignore
1539636821
Reply with quote  #2

1539636821
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1539636821
Hero Member
*
Offline Offline

Posts: 1539636821

View Profile Personal Message (Offline)

Ignore
1539636821
Reply with quote  #2

1539636821
Report to moderator
aleksej996
Sr. Member
****
Offline Offline

Activity: 420
Merit: 311


Do not trust the government


View Profile WWW
September 17, 2018, 11: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.

░░░░░░░▄▄▄▄▄▄
░░░░▄██████████▄
░░░██████████████
░░██████▐▌██████
█████░░░░░░░▀█████
██████▄▄░░▄▄░░██████
████████░░▀▀▄██████
████████░░▄▄▄░░█████
██████▀▀░░▀▀▀░░█████
█████░░░░░░░░█████
░░██████▐▌██████
░░░██████████████
░░░░▀██████████▀
░░░░░░░▀▀▀▀▀▀
░░░

                   BitCloak Bitcoin Mixer  
  BTC & BCH | API| MULTIADDRESS| PGP PROOF|  FAST MIX |  ESCROW|  MORE !

░░░░░░░▄▄▄▄▄▄
░░░░▄██████████▄
░░░██████████████
░░██████▐▌██████
█████░░░░░░░▀█████
██████▄▄░░▄▄░░██████
████████░░▀▀▄██████
████████░░▄▄▄░░█████
██████▀▀░░▀▀▀░░█████
█████░░░░░░░░█████
░░██████▐▌██████
░░░██████████████
░░░░▀██████████▀
░░░░░░░▀▀▀▀▀▀
░░░

GodlyWizard
Newbie
*
Offline Offline

Activity: 11
Merit: 4


View Profile
September 17, 2018, 12:20:53 PM
 #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.
aleksej996
Sr. Member
****
Offline Offline

Activity: 420
Merit: 311


Do not trust the government


View Profile WWW
September 17, 2018, 12:53:42 PM
Merited by DarkStar_ (4)
 #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.

░░░░░░░▄▄▄▄▄▄
░░░░▄██████████▄
░░░██████████████
░░██████▐▌██████
█████░░░░░░░▀█████
██████▄▄░░▄▄░░██████
████████░░▀▀▄██████
████████░░▄▄▄░░█████
██████▀▀░░▀▀▀░░█████
█████░░░░░░░░█████
░░██████▐▌██████
░░░██████████████
░░░░▀██████████▀
░░░░░░░▀▀▀▀▀▀
░░░

                   BitCloak Bitcoin Mixer  
  BTC & BCH | API| MULTIADDRESS| PGP PROOF|  FAST MIX |  ESCROW|  MORE !

░░░░░░░▄▄▄▄▄▄
░░░░▄██████████▄
░░░██████████████
░░██████▐▌██████
█████░░░░░░░▀█████
██████▄▄░░▄▄░░██████
████████░░▀▀▄██████
████████░░▄▄▄░░█████
██████▀▀░░▀▀▀░░█████
█████░░░░░░░░█████
░░██████▐▌██████
░░░██████████████
░░░░▀██████████▀
░░░░░░░▀▀▀▀▀▀
░░░

GodlyWizard
Newbie
*
Offline Offline

Activity: 11
Merit: 4


View Profile
September 17, 2018, 01:18:48 PM
Merited by DarkStar_ (4)
 #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.
seoincorporation
Legendary
*
Online Online

Activity: 1134
Merit: 1165


BtcBoss


View Profile
September 17, 2018, 04:01:02 PM
 #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.


.BitDice.               ▄▄███▄▄
           ▄▄██▀▀ ▄ ▀▀██▄▄
      ▄▄█ ▀▀  ▄▄█████▄▄  ▀▀ █▄▄
  ▄▄██▀▀     ▀▀ █████ ▀▀     ▀▀██▄▄
██▀▀ ▄▄██▀      ▀███▀      ▀██▄▄ ▀▀██
██  ████▄▄       ███       ▄▄████  ██
██  █▀▀████▄▄  ▄█████▄  ▄▄████▀▀█  ██
██  ▀     ▀▀▀███████████▀▀▀     ▀  ██
             ███████████
██  ▄     ▄▄▄███████████▄▄▄     ▄  ██
██  █▄▄████▀▀  ▀█████▀  ▀▀████▄▄█  ██
██  ████▀▀       ███       ▀▀████  ██
██▄▄ ▀▀██▄      ▄███▄      ▄██▀▀ ▄▄██
  ▀▀██▄▄     ▄▄ █████ ▄▄     ▄▄██▀▀
      ▀▀█ ▄▄  ▀▀█████▀▀  ▄▄ █▀▀
           ▀▀██▄▄ ▀ ▄▄██▀▀
               ▀▀███▀▀
        ▄▄███████▄▄
     ▄███████████████▄
    ████▀▀       ▀▀████
   ████▀           ▀████
   ████             ████
   ████ ▄▄▄▄▄▄▄▄▄▄▄ ████
▄█████████████████████████▄
██████████▀▀▀▀▀▀▀██████████
████                   ████
████                   ████
████                   ████
████                   ████
████                   ████
████▄                 ▄████
████████▄▄▄     ▄▄▄████████
  ▀▀▀█████████████████▀▀▀
        ▀▀▀█████▀▀▀
▄▄████████████████████████████████▄▄
██████████████████████████████████████
█████                            █████
█████                            █████
█████                            █████
█████                            █████
█████                     ▄▄▄▄▄▄▄▄▄▄
█████                   ▄█▀▀▀▀▀▀▀▀▀▀█▄
█████                   ██          ██
█████                   ██          ██
█████                   ██          ██
██████████████████▀▀███ ██          ██
 ████████████████▄  ▄██ ██          ██
   ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀ ██          ██
             ██████████ ██          ██
           ▄███████████ ██████▀▀██████
          █████████████  ▀████▄▄████▀
[/]
aleksej996
Sr. Member
****
Offline Offline

Activity: 420
Merit: 311


Do not trust the government


View Profile WWW
September 17, 2018, 04:18:23 PM
 #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.

░░░░░░░▄▄▄▄▄▄
░░░░▄██████████▄
░░░██████████████
░░██████▐▌██████
█████░░░░░░░▀█████
██████▄▄░░▄▄░░██████
████████░░▀▀▄██████
████████░░▄▄▄░░█████
██████▀▀░░▀▀▀░░█████
█████░░░░░░░░█████
░░██████▐▌██████
░░░██████████████
░░░░▀██████████▀
░░░░░░░▀▀▀▀▀▀
░░░

                   BitCloak Bitcoin Mixer  
  BTC & BCH | API| MULTIADDRESS| PGP PROOF|  FAST MIX |  ESCROW|  MORE !

░░░░░░░▄▄▄▄▄▄
░░░░▄██████████▄
░░░██████████████
░░██████▐▌██████
█████░░░░░░░▀█████
██████▄▄░░▄▄░░██████
████████░░▀▀▄██████
████████░░▄▄▄░░█████
██████▀▀░░▀▀▀░░█████
█████░░░░░░░░█████
░░██████▐▌██████
░░░██████████████
░░░░▀██████████▀
░░░░░░░▀▀▀▀▀▀
░░░

Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!