正在尝试将共同付款集成到我的网站上,然后使用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
AM新手并不真正知道事情的工作原理
问题是此处:
var client = new Coinpayments({
key: kfjdkjfkdfkf00d00, // <-- this line
secret: 009093403440349,
});
什么是kfjdkjfkdfkf00d00
?它既不是String
也不是Number
。这是一个未申报的变量。
因此,您将一个未申报的变量传递给Coinpayments
的构造函数,该变量从您提供的错误消息中判断为undefined
的值。
因此您的实际构造函数看起来像:
var client = new Coinpayments({
key: undefined,
secret: 009093403440349,
});
换句话说,您需要定义key
值。