我是Stackoverflow的新成员。所以,对不起,如果我还不知道如何将代码放入您设计的设计中,:s
我整夜试图找到一种方法来从client.initWallet('***', '***', function(err, wallet)
函数中提取比特币密钥。
您在楼下看到的console.log(address)
运行正常。但是,在}
之后,我无法访问数据。我真的不知道该怎么办。如果有人知道为什么我不能将值保留在“ address
”上...
感谢您的时间:D
const key = '*key*';
const secret = '*secretkey*';
blocktrail = require('blocktrail-sdk');
client = blocktrail.BlocktrailSDK({
apiKey: key,
apiSecret: secret,
network: 'BTC',
testnet: false
});
client.initWallet('*user*', '*password*',
function(err, wallet) {
wallet.getNewAddress(function (err, address) {
**console.log(address);**
});
});
答案 0 :(得分:0)
Bluebird可以将您的回调函数转换为返回Promise的函数
const bluebird = require('bluebird');
const key = '*key*';
const secret = '*secretkey*';
async function getWallet(){
blocktrail = require('blocktrail-sdk');
client = blocktrail.BlocktrailSDK({
apiKey: key,
apiSecret: secret,
network: 'BTC',
testnet: false
});
var asyncInitWallet = bluebird.promisify(client.initWallet);
var wallet = await asyncInitWallet('*user*', '*password*');
var asyncGetNewAddress = bluebird.promisify(wallet.getNewAddress);
var address = await asyncGetNewAddress();
console.log('address: ', address);
}
getWallet();