gpt4 book ai didi

javascript - Bitcore 创建交易脚本变量丢失

转载 作者:太空宇宙 更新时间:2023-11-04 01:59:07 26 4
gpt4 key购买 nike

我正在使用 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);

控制台向我显示了这个:

enter image description here

但是,当我使用 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 key 。否则将无法工作。

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com