node-bitcoin express rpc

3

1

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);}
});
/****

drcyw

Posted 2014-01-26T15:57:22.357

Reputation: 31

have you configured your bitcoin.conf file to expect incoming rpc traffic?Loourr 2014-01-26T17:12:52.803

oh, ok. I found some info on that. Going to try and figure out where it goes on an aws ebs setup. Thank youdrcyw 2014-01-26T18:33:07.567

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 2014-01-26T18:39:50.627

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. https://en.bitcoin.it/wiki/Running_Bitcoin

John T 2014-01-26T22:15:48.150

Also make sure you are properly configured, try visiting bitcoind in your browser and use the username and pass you set. http://127.0.0.1:8332

John T 2014-01-26T22:17:54.483

@JacobTorba Maybe write an answer from the comments? :)Murch 2014-02-09T08:54:45.497

Answers

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.

John T

Posted 2014-01-26T15:57:22.357

Reputation: 2 759