在使用bitcoinjs-lib时,我得到的是getAddress()不起作用

时间:2018-08-03 13:07:59

标签: javascript node.js blockchain bitcoin

下面是代码。

const bitcoin = require('bitcoinjs-lib');     让testnet = bitcoin.networks.testnet;

let keypair = bitcoin.ECPair.makeRandom({network: testnet});

let addr = keypair.getAddress();
let  pk = keypair.toWIF();

enter image description here

2 个答案:

答案 0 :(得分:2)

您尝试过吗:

class ExternalClass
{
    public int ExternalMethod(int input)
    {
        // do a thing
    }
}

public class WrapperClass
{
    private ExternalClass external;

    public WrapperClass(ExternalClass external)
    {
        this.external = external;
    }            

    public int WrapperMethod(int input) {
        // do the verification or checks that you need here
        return this.external(input);
    }

}

这似乎是the definitive example at github所做的。

答案 1 :(得分:2)

只需将网络参数直接传递给ECPair.makeRandom即可,而无需包装对象,您将在那里:)

const bitcoin = require('bitcoinjs-lib');

let testnet = bitcoin.networks.testnet;
let keypair = bitcoin.ECPair.makeRandom(testnet);

let addr = keypair.getAddress();
let pk = keypair.toWIF();