Bitcoin-Node-Api icon indicating copy to clipboard operation
Bitcoin-Node-Api copied to clipboard

How to run bitcoin-node-api example ?

Open Smurfy303 opened this issue 7 years ago • 2 comments

When I am trying to run below example as

var bitcoinapi = require('bitcoin-node-api');
var express = require('express');
var app = express();

var wallet = {
  host: 'localhost',
  port: 8332,
  user: 'username',
  pass: 'password'
};
bitcoinapi.setWalletDetails(wallet);
app.use('/bitcoin/api', bitcoinapi.app); //Bind the middleware to any chosen url

app.get('/getApi' , (req,res) => {

	var url = 'http://localhost:3000/bitcoin/api/getinfo';
	console.log('Url is :->',url);

	var request = require('request');
	request(url, function (error, response, body) {
		console.log('response-->',response);
		console.log('Error-->',error);
		
	  if (!error && response.statusCode == 200) {
	  	//var response = JSON.parse(body);
	    res.send(response); 
	  }
	  else { 
	    console.log("Error "+error);
	  }
	});
})
app.listen(3000,(port)=>{
	console.log('Port at 3000');
});

and trying to run : node app.js it giving me an error as,

{ Error: connect ECONNREFUSED 127.0.0.1:8332
    at Object._errnoException (util.js:1022:11)
    at _exceptionWithHostPort (util.js:1044:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
  code: 'ECONNREFUSED',
  errno: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 8332 }

can you please tell me how to run bitcoin-node-api ??

Smurfy303 avatar Apr 03 '18 10:04 Smurfy303

Do you have a running blockchain on the server/machine you're running this file?

Manbearpixel avatar May 18 '18 22:05 Manbearpixel

@Manbearpixel I am having the same problem and I do have blockchain running on the machine

NandiniSarda avatar Oct 26 '20 07:10 NandiniSarda