我正在使用Bitcore尝试进行此示例中的交易:

https://github.com/bitpay/bitcore-lib/blob/master/docs/examples.md(上面写着“创建交易”)。

但是,“脚本”部分存在一些问题,这是我的代码:

var privateKey = new bitcore.PrivateKey('the private key :P');
var address = bitcore.Address.fromString('1PP4jkxPhJVDP9cEkdbHXvXCiFuiEZTjtb');
var script = bitcore.Script.buildPublicKeyHashOut(address);


控制台向我显示了这一点:

javascript - Bitcore创建事务脚本变量丢失-LMLPHP

但是,当我使用JSON.stringify(script)时,我得到了:

{
    "chunks": [{
        "opcodenum": 118
    }, {
        "opcodenum": 169
    }, {
        "buf": {
            "type": "Buffer",
            "data": [245, 127, 9, 190, 134, 210, 30, 178, 246, 47, 189, 61, 92, 64, 165, 177, 207, 158, 104, 156
            ]
        },
        "len": 20,
        "opcodenum": 20
    }, {
        "opcodenum": 136
    }, {
        "opcodenum": 172
    }],
    "_network": {
        "name": "live
        net ","
        alias ":"
        mainnet ","
        pubkeyhash ":0,"
        privatekey ":128,"
        scripthash ":5,"
        xpubkey ":
        76067358,
        "xprivkey": 76066276,
        "networkMagic": {
            "type": "Buffer",
            "data": [249, 190, 180, 217]
        },
        "port": 8333,
        "dnsSeeds": ["seed.bitcoin.sipa.be", "dnsseed.bluematt.me", "dns
                seed.bitcoin.dashjr.org ","
                seed.bitcoinstats.com ","
                seed.bitnodes.io ","
                bitseed.xf2
                .org "]
    }
}


这些都不像用来在Bitcore的github库上进行事务的“脚本”变量一样。

最佳答案

var privateKey = new bitcore.PrivateKey('the private key :P');
var address = privateKey.toWIP().toAddress();
var script = bitcore.Script.buildPublicKeyHashOut(address);


可能会有所帮助!

您需要使用相同的私钥创建地址,并且该地址应该是WIP密钥。否则它将无法正常工作。

关于javascript - Bitcore创建事务脚本变量丢失,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46698711/

10-09 21:20