4

I can't get the node-bitcoin rpc module running correctly in my express app... Either I get a connection refused error or I get a invalid params -32602

Here's a little code snipped from my app.js file. Can somebody help me out on what I'm doing wrong here. FYI, I do have port 8332 and 8333 open on nginx

/******* THIS GIVES ME INVALID PARAMS from -32602 ******/
var net = require('net');
var server = net.createServer(function(c) { //'connection' listener
console.log('server connected');
});
server.listen(8332, function() { //'listening' listener
console.log('server bound');
});

var bitcoinClient = new bitcoin.Client({
host: 'localhost',
port: 8332,
user: 'username',
pass: 'password'
});

bitcoinClient.getInfo(function(e, info){
if(e){ return console.log(e);}
});
/****************************************************************/

/******* THIS GIVES ME CONNECTION REFUSED ******/

var bitcoinClient = new bitcoin.Client({
host: 'localhost',
port: 8332,
user: 'username',
pass: 'password'
});

bitcoinClient.getInfo(function(e, info){
if(e){ return console.log(e);}
});
/****
6
  • have you configured your bitcoin.conf file to expect incoming rpc traffic?
    – Loourr
    Jan 26, 2014 at 17:12
  • oh, ok. I found some info on that. Going to try and figure out where it goes on an aws ebs setup. Thank you
    – drcyw
    Jan 26, 2014 at 18:33
  • but just to be clear.... I'm not wanting to accept rpc calls or anything like that (no mining either)... I just want to be able to hit the bitcoind api. Do I still need a bit coin.conf file for that and if so do I need to specify server = 0 ?
    – drcyw
    Jan 26, 2014 at 18:39
  • Yes you still need bitcoin.conf configured properly to give it API commands, see sample bitcoin.conf and uncomment and configure all relevant parameters. For your case you probably need server=1, rpcuser and rpcpassword set. en.bitcoin.it/wiki/Running_Bitcoin
    – John T
    Jan 26, 2014 at 22:15
  • Also make sure you are properly configured, try visiting bitcoind in your browser and use the username and pass you set. 127.0.0.1:8332
    – John T
    Jan 26, 2014 at 22:17

1 Answer 1

3

As Murch suggested in comments, I better leave this as an answer.

What I think your problem is that you haven't configured your bitcoin.conf file. You can see all the parameters and explanation of em' thoughtfully provided by the Bitcoin wiki here. See that example bitcoin.conf? It has all the parameters commented out with the # sign. Just uncomment them by removing the hash and fill in your configuration.

To use the api you are going to need server=1 to enable api commands, rpcuser=<username> and rpcpassword=<your secure password to be able to actually connect.

Now test it

It's easy to test your Bitcoind configuration settings with a browser, just load up the address of your Bitcoind in a browser like so: http://127.0.0.1:8332. It should throw a username and password dialog if everything is correct.

Note: You will need to enable rpcallowip=<ip> to allow connections from other than your own machine. This is also really dangerous and I advise against this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.