0

我正在尝试将 coinpayments 集成到我的网站中,我正在使用 express js 来运行它我已经浏览了 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

我是新手,不太清楚事情是如何运作的

4

1 回答 1

1

问题是这里的这一部分:

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

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

因此,您将一个未声明的变量传递给构造函数,Coinpayments该变量的值undefined由您提供的错误消息判断。

所以你的实际构造函数看起来像:

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

换句话说,你需要定义你的key价值。

于 2018-02-12T16:19:59.627 回答