比特幣(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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。