比特币(Bitcoin) RPC Rawtransactions API中getrawtransaction的用法及代码示例。
用法:
getrawtransaction "txid" ( verbose "blockhash" )
返回原始交易数据。
默认情况下,此函数仅适用于内存池事务。当使用blockhash参数调用时,如果指定的块可用并且在该块中找到了该事务,则getrawtransaction将返回该事务。如果在不使用blockhash参数的情况下调用该函数,则getrawtransaction将返回该事务(如果该事务位于内存池中),或者如果启用了-txindex且该事务位于区块链中的某个块中。
提示:将gettransaction用于钱包交易。
如果verbose为‘true’,则返回一个对象,其中包含有关‘txid’的信息。
如果verbose为‘false’或省略,则返回一个序列化的字符串,即‘txid’的hex-encoded数据。
参数1 - txid
类型:字符串,必填
交易编号
参数2 - verbose
类型:布尔值,可选,默认= false
如果为false,则返回字符串,否则返回json对象
参数3 - blockhash
类型:字符串,可选
在其中寻找交易的区块
结果(如果未设置冗长或设置为false)
名称 |
类型 |
描述 |
---|---|---|
data |
string |
‘txid’的序列化hex-encoded数据 |
结果(如果将verbose设置为true)
{
"in_active_chain": b, (bool) Whether specified block is in the active chain or not (only present with explicit "blockhash" argument)
"hex" : "data", (string) The serialized, hex-encoded data for 'txid'
"txid" : "id", (string) The transaction id (same as provided)
"hash" : "id", (string) The transaction hash (differs from txid for witness transactions)
"size" : n, (numeric) The serialized transaction size
"vsize" : n, (numeric) The virtual transaction size (differs from size for witness transactions)
"weight" : n, (numeric) The transaction's weight (between vsize*4-3 and vsize*4)
"version" : n, (numeric) The version
"locktime" : ttt, (numeric) The lock time
"vin" : [ (array of json objects)
{
"txid": "id", (string) The transaction id
"vout": n, (numeric)
"scriptSig": { (json object) The script
"asm": "asm", (string) asm
"hex": "hex" (string) hex
},
"sequence": n (numeric) The script sequence number
"txinwitness": ["hex", ...] (array of string) hex-encoded witness data (if any)
}
,...
],
"vout" : [ (array of json objects)
{
"value" : x.xxx, (numeric) The value in BTC
"n" : n, (numeric) index
"scriptPubKey" : { (json object)
"asm" : "asm", (string) the asm
"hex" : "hex", (string) the hex
"reqSigs" : n, (numeric) The required sigs
"type" : "pubkeyhash", (string) The type, eg 'pubkeyhash'
"addresses" : [ (json array of string)
"address" (string) bitcoin address
,...
]
}
}
,...
],
"blockhash" : "hash", (string) the block hash
"confirmations" : n, (numeric) The confirmations
"blocktime" : ttt (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)
"time" : ttt, (numeric) Same as "blocktime"
}
示例
bitcoin-cli getrawtransaction "mytxid"
bitcoin-cli getrawtransaction "mytxid" true
curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getrawtransaction", "params": ["mytxid", true] }' -H 'content-type: text/plain;' http://127.0.0.1:8332/
bitcoin-cli getrawtransaction "mytxid" false "myblockhash"
bitcoin-cli getrawtransaction "mytxid" true "myblockhash"
相关用法
- Bitcoin analyzepsbt用法及代码示例
- Bitcoin combinepsbt用法及代码示例
- Bitcoin combinerawtransaction用法及代码示例
- Bitcoin converttopsbt用法及代码示例
- Bitcoin createpsbt用法及代码示例
- Bitcoin createrawtransaction用法及代码示例
- Bitcoin decodepsbt用法及代码示例
- Bitcoin decoderawtransaction用法及代码示例
- Bitcoin decodescript用法及代码示例
- Bitcoin finalizepsbt用法及代码示例
- Bitcoin fundrawtransaction用法及代码示例
- Bitcoin joinpsbts用法及代码示例
- Bitcoin sendrawtransaction用法及代码示例
- Bitcoin signrawtransactionwithkey用法及代码示例
- Bitcoin testmempoolaccept用法及代码示例
- Bitcoin utxoupdatepsbt用法及代码示例
注:本文由纯净天空筛选整理自bitcoin.org大神的英文原创作品 Bitcoin getrawtransaction。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。