Bitcoin — Blockchain RPCs (3/3)
API reference for Bitcoin. All methods ->
Blockchain RPCs
gettxoutproof
Returns a hex-encoded proof that “txid” was included in a block.
NOTE: By default this function only works sometimes. This is when there is an unspent output in the utxo for this transaction. To make it always work, you need to maintain a transaction index, using the -txindex command line option or specify the block in which the transaction is included manually (by blockhash).
gettxoutproof ["txid",...] ( "blockhash" )
Parameters
-
id(string; required): a request ID (example: test). -
jsonrpc(string; required): a JSON RPC spec used (example: 2.0). -
method(string; required): a method used for the request. -
params(array; required):-
<txid>(array of strings: required): the txids to filter.["txid", (string) A transaction hash...] -
<blockhash>(string; optional): if specified, looks for txid in the block with this hash.
-
Returns
A string that is a serialized, hex-encoded data for the proof.
Request example
curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "gettxoutproof",
"params": [["c7f32887779200fec23a0f4ebe73bed003f9ab8a46c2b549320c3c5cb78c7dc9"], "000000000000000000034e30310c8bf30133e41ae3ae189f987e509901409bf7"]
Response example
{
"result": "008035222f854ca799cc749ca6d54a9ab85793b130a95348fe6e00000000000000000000badfdb8bab19d4ab1f08da2c98122c7d25586ba56b9c13cce8325eb42948fb8028a644669a62031723892528750d00000dc97d8cb75c3c0c3249b5c2468aabf903d0be73be4e0f3ac2fe0092778728f3c7096a1ace4290e6cfb9ab99245aee7fab74f6e6393ef47932d1b6cb494d60451780ecc5be308320b45fd9f07b6cffe1a6b7143ae9e2d134a4292dd937ff83d92b5a683483be79cabafd107330094c049ef166fad38a395b6bc4f58de82f0d5cbd479483b11d489ccb87e20cf97451419453495d1492e32bb9c0539c9a92885d7c2310ef802b85611f6340a7f99c36f04e769ab50bb00048791b16091870f817c503d46587bd48aa6bd895ea6ce9eb3fa06a86b432a40afbf27d879c09093ca03586284ac2b64b252b32be440a683beaf2f672efaf1cb36a429fa2a2cbe0800373a72857c1af218d71e4295ebeabdb80ca35b41f5d3a91c78a186fc76b01690d6f7a89a6912d4528a0072a5945f6a3f94b8fbc293964bdab3b9fb70ea0e7be6caa25f15f366a9473bbf55f69335b7dc642472efeb4feeaa0fafedf70c5a4f7dc370bddd972db84dd9fb5e82fced3cdef20bc98ae178fc8aedb8a2448652c6ce32cbe82d4859c7004d38db06d61b7b5014a89ad9160ec39adfb21b7a92d7f84525404ff1f0000",
"error": null,
"id": "test"
}
verifytxoutproof
Verifies that a proof points to a transaction in a block.
Verifies that a proof points to a transaction in a block, returning the transaction it commits to and throwing an RPC error if the block is not in our best chain.
verifytxoutproof "proof"
Parameters
-
id(string; required): a request ID (example: test). -
jsonrpc(string; required): a JSON RPC spec used (example: 2.0). -
method(string; required): a method used for the request. -
params(array; required):<proof>(string; required): the hex-encoded proof generated bygettxoutproof.
Returns
[ (json array)
"hex", (string) The txid(s) which the proof commits to, or empty array if the proof can not be validated.
...
]
Request example
curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "verifytxoutproof",
"params": ["008035222f854ca799cc749ca6d54a9ab85793b130a95348fe6e00000000000000000000badfdb8bab19d4ab1f08da2c98122c7d25586ba56b9c13cce8325eb42948fb8028a644669a62031723892528750d00000dc97d8cb75c3c0c3249b5c2468aabf903d0be73be4e0f3ac2fe0092778728f3c7096a1ace4290e6cfb9ab99245aee7fab74f6e6393ef47932d1b6cb494d60451780ecc5be308320b45fd9f07b6cffe1a6b7143ae9e2d134a4292dd937ff83d92b5a683483be79cabafd107330094c049ef166fad38a395b6bc4f58de82f0d5cbd479483b11d489ccb87e20cf97451419453495d1492e32bb9c0539c9a92885d7c2310ef802b85611f6340a7f99c36f04e769ab50bb00048791b16091870f817c503d46587bd48aa6bd895ea6ce9eb3fa06a86b432a40afbf27d879c09093ca03586284ac2b64b252b32be440a683beaf2f672efaf1cb36a429fa2a2cbe0800373a72857c1af218d71e4295ebeabdb80ca35b41f5d3a91c78a186fc76b01690d6f7a89a6912d4528a0072a5945f6a3f94b8fbc293964bdab3b9fb70ea0e7be6caa25f15f366a9473bbf55f69335b7dc642472efeb4feeaa0fafedf70c5a4f7dc370bddd972db84dd9fb5e82fced3cdef20bc98ae178fc8aedb8a2448652c6ce32cbe82d4859c7004d38db06d61b7b5014a89ad9160ec39adfb21b7a92d7f84525404ff1f0000"]
}'
Response example
{
"result": [
"c7f32887779200fec23a0f4ebe73bed003f9ab8a46c2b549320c3c5cb78c7dc9"
],
"error": null,
"id": "test"
}