Node.js区块链比特币api

时间:2015-07-24 11:55:41

标签: node.js bitcoin

所以我想用这个:(取自他们的API网站 - > node.js文档) https://github.com/blockchain/api-v1-client-node

收到付款: https://github.com/blockchain/api-v1-client-node/blob/master/docs/Receive.md

var blockchain = require('blockchain.info');
var identifier = 'myidentifier'; 
var password = 'mypassword';
var myWallet = new blockchain.MyWallet(identifier, password);
var myBTCadress = '14Q3ufL1BUHtWskBKtsshVDATRY65TaJMB';

好的,接收部分:

var receive = new blockchain.Receive( [confirmations: 1], ? ); // What do I need to put here?

文件说: callbackURL:应该向其发送回调的url(字符串)

我不明白应该去哪个网址?!

1 个答案:

答案 0 :(得分:0)

回调网址应该是重定向回您网站的网址。因此,使用区块链设置回调网址,如...

https://www.yoursite.com/callback/blockchain

假设您在应用中使用了类似Express的内容,请制作类似的路线。

app.get('/callback/blockchain', function (req, res) {

// Stuff here  

});

你将需要包括

var https = require('https'); 

那样你就可以在里面设置你的逻辑......

// Stuff here
 var options = {
    host : 'api.blockchain.info',
    path : '/some/path/',
    port : 443,
    method : 'GET'
  }
 var request = https.request(options, function(response){
    var body = ""
    response.on('data', function(data) {
      body += data;
    });
    response.on('end', function() {
      res.send(JSON.parse(body));
    });
  });
  request.on('error', function(e) {
    console.log('Problem with request: ' + e.message);
  });
  request.end();

例如,您将在app.get('whateverurl')设置为的任何页面上输出您在json中请求的内容。