BlockchainTransaction (for Bitcoin)
BlockchainTransaction[assoc]
表示一个根据关联 assoc 中的分量构建的比特币区块链交易.
更多信息
- 给出比特币区块链交易的符号表示;它不提交交易,并且交易是未签名的.
- BlockchainTransaction[…][prop] 给出交易的属性 prop 的值.
- 必须给出以下元素:
-
"Inputs" 输入列表,以关联形式给出 "Outputs" 输出列表,以关联形式给出 - 也可以给出以下其他元素:
-
"Version" 交易版本号(默认:1) "LockTime" 最早添加交易的时间或区块(默认:0) - "Inputs" 列表中的每个关联必须含有下面的项:
-
"TransactionID" 之前交易的哈希 "Index" 上一个交易输出中的索引 - 也可以给出以下其他项:
-
"ScriptString" "" 解锁脚本,也称为 scriptSig "SignatureHash" All 签名哈希 flag - "SignatureHash" 的可能的值包括:
-
All 对所有输入和输出应用签名 None 对所有输入应用签名,但不对输出应用签名 "Single" 对所有输入和输出应用签名,用同一个索引号作为已签名输入 "AllAnyoneCanPay" 对一个输入和所有输出应用签名 "NoneAnyoneCanPay" 对一个输入应用签名,但不对输出应用签名 "SingleAnyoneCanPay" 用同样的索引号对一个输入和输出应用签名 - 对于 Pay-to-Public-Key-Hash (P2PKH) 交易,"Outputs" 列表中的每个关联必须含有下面的项:
-
"Amount" 要转发的比特币的数量 "Address" 转发的目标 P2PKH 地址 - 对于普通的比特币交易,可以给出自定义锁定脚本,"Outputs" 列表中的每个关联必须含有下面的项:
-
"Amount" 要转发的比特币的数量 "ScriptString" 字符串形式的比特币脚本 - BlockchainTransaction 可表示 Bitcoin mainnet(默认)和 testnet 交易. 要想指定这些网络,请在相应的关联中指定 "BlockchainBase" 的值或使用 BlockchainBase 选项.
范例
打开所有单元 关闭所有单元基本范例 (1)
创建一个表示 Pay-to-Public-Key-Hash 交易的比特币交易对象:
BlockchainTransaction[<|"Inputs" -> {<|"TransactionID" -> "9bef194418607318673caaf8f45d52fb60e8c8586e6ce8414c377a279ca14399", "Index" -> 0|>}, "Outputs" -> {<|"Amount" -> Quantity[0.0002, "Bitcoins"], "Address" -> "munDTMqa9V9Uhi3P21FpkY8UfYzvQqpmoQ"|>, <|"Amount" -> Quantity[0.16223, "Bitcoins"], "Address" -> "mo9QWLSJ1g1ENrTkhK9SSyw7cYJfJLU8QH"|>}, "BlockchainBase" -> {"Bitcoin", "Testnet"}|>]范围 (4)
自定义非标准腳本 (2)
BlockchainTransaction[<|"BlockchainBase" -> {"Bitcoin", "Testnet"},
"Inputs" -> {
<|"TransactionID" -> "adf7388f15cc5b115640f1e13e648b9babaee2d32c24185bc46917fc91d03d11", "Index" -> 1|>
}, "Outputs" -> {
<|"Amount" -> 0.0001, "Address" -> "mkHGstoUaDWzGxag29MEnp8WJPpfA45omK"|>,
<|"Amount" -> 0.0008, "ScriptString" -> "OP_3 OP_ADD OP_5 OP_EQUAL"|>
}|>]BlockchainTransaction[<|"BlockchainBase" -> {"Bitcoin", "Testnet"},
"Inputs" -> {
<|"TransactionID" -> "80853fd19713110bf36a778981635c8208669736c81b622a5d2c0efd30ecc4f1", "Index" -> 1, "ScriptString" -> "OP_2"|>
}, "Outputs" -> {
<|"Amount" -> 0.0007, "Address" -> "mgPhDaCzXcm4gmkxfz9sZKvpabmNGdLj52"|>
}|>]簽名哈希 (1)
在交易的输入中使用不同的 "SignatureHash" 值:
BlockchainTransaction[<|"BlockchainBase" -> {"Bitcoin", "Testnet"},
"Inputs" -> {
<|"TransactionID" -> "0ad5d33acf0e604c377f134ed7f4f8537d80cbb4fb90397c2bd99dc46a935dc1", "Index" -> 0, "SignatureHash" -> "All"|>,
<|"TransactionID" -> "fdd13f77b31924490f282c0cb8433cd75a20a55f81c9d5a8ad5eb2bf4819c191", "Index" -> 0, "SignatureHash" -> "Single"|>,
<|"TransactionID" -> "ec8169870d16d96d1d498a4f344a7db6e98e79cb1e51e7c553b3e200549e68bb", "Index" -> 0, "SignatureHash" -> "None"|>
}, "Outputs" -> {
<|"Amount" -> 0.0022, "Address" -> "mkHGstoUaDWzGxag29MEnp8WJPpfA45omK"|>,
<|"Amount" -> 0.0001, "Address" -> "mgPhDaCzXcm4gmkxfz9sZKvpabmNGdLj52"|>
}|>]時间锁定的交易 (1)
BlockchainTransaction[<|"BlockchainBase" -> {"Bitcoin", "Testnet"},
"LockTime" -> 2000000,
"Inputs" -> {
<|"TransactionID" -> "20e32abc358790836664a2b5f479a7a72ef9995d3bdd966912593e9ae4e98997", "Index" -> 1|>
}, "Outputs" -> {
<|"Amount" -> 0.0008, "Address" -> "mkHGstoUaDWzGxag29MEnp8WJPpfA45omK"|>,
<|"Amount" -> 0.0001, "Address" -> "mgPhDaCzXcm4gmkxfz9sZKvpabmNGdLj52"|>
}|>]选项 (2)
BlockchainBase (2)
Mainnet (1)
BlockchainTransaction[<|"Inputs" -> {<|"TransactionID" -> "8295cd40010918aadbc2b87cff849d91ad771677a65c6fe940fa79814554dee5", "Index" -> 2|>}, "Outputs" -> {<|"Amount" -> Quantity[1.1644, "Bitcoins"], "Address" -> "1FX4cYyrwGo52qumivnFY3zRqQAYHqwL9v"|>, <|"Amount" -> Quantity[0.99923, "Bitcoins"], "Address" -> "13pwhpMP7KnHBprsJz5FkkqWioTpr13ZbQ"|>}|>, BlockchainBase -> "Bitcoin"]Testnet (1)
BlockchainTransaction[<|"Inputs" -> {<|"TransactionID" -> "9bef194418607318673caaf8f45d52fb60e8c8586e6ce8414c377a279ca14399", "Index" -> 0|>}, "Outputs" -> {<|"Amount" -> Quantity[0.0002, "Bitcoins"], "Address" -> "munDTMqa9V9Uhi3P21FpkY8UfYzvQqpmoQ"|>, <|"Amount" -> Quantity[0.16223, "Bitcoins"], "Address" -> "mo9QWLSJ1g1ENrTkhK9SSyw7cYJfJLU8QH"|>}|>, BlockchainBase -> {"Bitcoin", "Testnet"}]应用 (1)
创建一个 Bitcoin Pay-to-Public-Key-Hash BlockchainTransaction:
btcTX = BlockchainTransaction[<|
"Inputs" -> {
<|"TransactionID" -> "79bd95a5c087cfc33904020b3cd31b11b97be7751c8a1ca57c5313d4ac848830", "Index" -> 0|>},
"Outputs" -> {
<|"Amount" -> Quantity[0.005, "Bitcoins"], "Address" -> "mgPhDaCzXcm4gmkxfz9sZKvpabmNGdLj52"|>,
<|"Amount" -> Quantity[0.044, "Bitcoins"], "Address" -> "mkHGstoUaDWzGxag29MEnp8WJPpfA45omK"|>},
"BlockchainBase" -> {"Bitcoin", "Testnet"}|>]btcTXSigned = BlockchainTransactionSign[btcTX, "cVN2fsWXoxMkPGx5EL7X6grykQ3VSDfHPUg3CJhD8AC9pJ5y8Nhi"]BlockchainTransactionSubmit[btcTXSigned]可能存在的问题 (2)
Insuficient Amount (1)
如果提供的输入引用的是未消费交易的输出,其金额不足以达到总输出金额,将返回 $Failed 输出:
BlockchainTransaction[<|"Inputs" -> {<|"TransactionID" -> "9bef194418607318673caaf8f45d52fb60e8c8586e6ce8414c377a279ca14399", "Index" -> 0|>}, "Outputs" -> {<|"Amount" -> Quantity[10, "Bitcoins"], "Address" -> "mkHGstoUaDWzGxag29MEnp8WJPpfA45omK"|>, <|"Amount" -> Quantity[0.16223, "Bitcoins"], "Address" -> "mo9QWLSJ1g1ENrTkhK9SSyw7cYJfJLU8QH"|>}, "BlockchainBase" -> {"Bitcoin", "Testnet"}|>]错误的输出地址 (1)
如果提供的是无效的地址,将返回 $Failed 输出:
BlockchainTransaction[<|"Inputs" -> {<|"TransactionID" -> "9bef194418607318673caaf8f45d52fb60e8c8586e6ce8414c377a279ca14399", "Index" -> 0|>}, "Outputs" -> {<|"Amount" -> Quantity[0.0002, "Bitcoins"], "Address" -> "AAAAAA"|>, <|"Amount" -> Quantity[0.16223, "Bitcoins"], "Address" -> "mo9QWLSJ1g1ENrTkhK9SSyw7cYJfJLU8QH"|>}, "BlockchainBase" -> {"Bitcoin", "Testnet"}|>]相关指南
-
▪
- 使用比特币区块链
历史
2019年引入 (12.0)
文本
Wolfram Research (2019),BlockchainTransaction,Wolfram 语言函数,https://reference.wolfram.com/language/ref/blockchain/BlockchainTransaction-Bitcoin.html.
CMS
Wolfram 语言. 2019. "BlockchainTransaction." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/ref/blockchain/BlockchainTransaction-Bitcoin.html.
APA
Wolfram 语言. (2019). BlockchainTransaction. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/blockchain/BlockchainTransaction-Bitcoin.html 年
BibTeX
@misc{reference.wolfram_2026_blockchaintransaction, author="Wolfram Research", title="{BlockchainTransaction}", year="2019", howpublished="\url{https://reference.wolfram.com/language/ref/blockchain/BlockchainTransaction-Bitcoin.html}", note=[Accessed: 16-August-2026]}
BibLaTeX
@online{reference.wolfram_2026_blockchaintransaction, organization={Wolfram Research}, title={BlockchainTransaction}, year={2019}, url={https://reference.wolfram.com/language/ref/blockchain/BlockchainTransaction-Bitcoin.html}, note=[Accessed: 16-August-2026]}