如何在节点js中使用Coinpayments API

时间:2018-02-09 07:45:22

标签: node.js api express

我正在尝试将筹款整合到我的网站中使用快递j来运行它我已经通过了npm文档,但它似乎仍然不清楚我和我尝试运行一些代码但仍然没有显示。任何帮助都非常感谢。

var express           = require("express"),
      app                 = express(),
      coinpayments = require("coinpayments"),
      bodyparser      = require("body-parser")

      app.use(bodyParser.urlencoded({extended: true}));
var Coinpayments = require('coinpayments');
var client = new Coinpayments({
      key: kfjdkjfkdfkf00d00,
      secret: 009093403440349,
});

client.getBasicInfo(function(error,result){
    if(error){
        console.log(error)
    } else{
        console.log(result)
    }
})

在我的命令行中抛出错误

sniperfillipo:~/workspace/bitcointest/main $ node crypto.js 
/home/ubuntu/workspace/bitcointest/main/node_modules/coinpayments/lib/index.js:28
            throw new Error('Missing public key and/or secret');
            ^

Error: Missing public key and/or secret
    at new CoinPayments (/home/ubuntu/workspace/bitcointest/main/node_modules/coinpayments/lib/index.js:28:19)
    at Object.<anonymous> (/home/ubuntu/workspace/bitcointest/main/crypto.js:235:14)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:389:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:504:3

对此人来说,新手并不确切知道如何运作

1 个答案:

答案 0 :(得分:1)

问题在于此部分:

var client = new Coinpayments({
      key: kfjdkjfkdfkf00d00,   // <-- this line
      secret: 009093403440349,
});

什么是kfjdkjfkdfkf00d00?它既不是String也不是Number。这是一个未声明的变量。

所以你将一个未声明的变量传递给Coinpayments的构造函数,它从你提供的错误消息中得到undefined的值。

所以你的实际构造函数如下:

var client = new Coinpayments({
      key: undefined,
      secret: 009093403440349,
});

换句话说,您需要定义key值。