Bitcoin — Raw transactions RPCs, Util RPCs, Wallet RPCs
API reference for Bitcoin. All methods ->
Raw transactions RPCs
analyzepsbt
Analyzes and provides information about the current status of a PSBT and its inputs.
analyzepsbt "psbt"
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):<psbt>(string; required): a base64 string of a PSBT.
Returns
{ (json object)
"inputs" : [ (json array)
{ (json object)
"has_utxo" : true|false, (boolean) Whether a UTXO is provided
"is_final" : true|false, (boolean) Whether the input is finalized
"missing" : { (json object, optional) Things that are missing that are required to complete this input
"pubkeys" : [ (json array, optional)
"hex", (string) Public key ID, hash160 of the public key, of a public key whose BIP 32 derivation path is missing
...
],
"signatures" : [ (json array, optional)
"hex", (string) Public key ID, hash160 of the public key, of a public key whose signature is missing
...
],
"redeemscript" : "hex", (string, optional) Hash160 of the redeemScript that is missing
"witnessscript" : "hex" (string, optional) SHA256 of the witnessScript that is missing
},
"next" : "str" (string, optional) Role of the next person that this input needs to go to
},
...
],
"estimated_vsize" : n, (numeric, optional) Estimated vsize of the final signed transaction
"estimated_feerate" : n, (numeric, optional) Estimated feerate of the final signed transaction in BTC/kB. Shown only if all UTXO slots in the PSBT have been filled
"fee" : n, (numeric, optional) The transaction fee paid. Shown only if all UTXO slots in the PSBT have been filled
"next" : "str", (string) Role of the next person that this psbt needs to go to
"error" : "str" (string, optional) Error message (if there is one)
}
Request example
curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "analyzepsbt",
"params": ["cHNidP8BAFUCAAAAATK/5HXt1hQqK9Sy/NYfp/TPW/RZlM5LbV0v76TH56nhAAAAAAD9////AUBCDwAAAAAAGXapFGLpB7FcvyfVQlOZ6/bw+1DruI8YiKwAAAAAAAAA"]
}'
Response example
{
"result": {
"inputs": [
{
"has_utxo": false,
"is_final": false,
"next": "updater"
}
],
"next": "updater"
},
"error": null,
"id": "test"
}
combinepsbt
Combines multiple partially signed Bitcoin transactions into one transaction.
Implements the Combiner role.
combinepsbt ["psbt",...]
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):-
<txs>(array of strings; required): the base64 strings of partially signed transactions.["psbt", (string) A base64 string of a PSBT...]
-
Returns
The base64-encoded partially signed transaction.
Request example
curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "combinepsbt",
"params": ["mybase64_1", "mybase64_2", "mybase64_3"]
}'
combinerawtransaction
Combines multiple partially signed transactions into one transaction.
The combined transaction may be another partially signed transaction or a fully signed transaction.
combinerawtransaction ["hexstring",...]
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):-
<txs>(array of strings; required): the hex strings of partially signed transactions.["hexstring", (string) A hex-encoded raw transaction...]
-
Returns
The hex-encoded raw transaction with signatures.
Request example
curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "combinerawtransaction",
"params": ["mybase64_1", "mybase64_2", "mybase64_3"]
}'
converttopsbt
Converts a network serialized transaction to a PSBT.
This should be used only with createrawtransaction and fundrawtransaction. createpsbt and walletcreatefundedpsbt should be used for new applications.
converttopsbt "hexstring" ( permitsigdata iswitness )
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):<hexstring>(string; required): the hex string of a raw transaction.<permitsigdata>(boolean; optional; default=false): iftrue, any signatures in the input will be discarded and conversion will continue. Iffalse, RPC will fail if any signatures are present.<iswitness>(boolean; optional; default=depends on heuristic tests): whether the transaction hex is a serialized witness transaction. Ifiswitnessis not present, heuristic tests will be used in decoding. If true, only witness deserialization will be tried. If false, only non-witness deserialization will be tried. This boolean should reflect whether the transaction has inputs (e.g. fully valid, or on-chain transactions), if known by the caller.
Returns
The resulting raw transaction (base64-encoded string).
Request example
Create a transaction:
curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "createrawtransaction",
"params": [[{"txid":"myid","vout":0}],[{"address":0.01}]]
}'
Convert the transaction to PSBT:
curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "converttopsbt",
"params": ["020000000132bfe475edd6142a2bd4b2fcd61fa7f4cf5bf45994ce4b6d5d2fefa4c7e7a9e10000000000fdffffff0140420f00000000001976a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac00000000"]
}'
Response example
{
"result": "cHNidP8BAFUCAAAAATK/5HXt1hQqK9Sy/NYfp/TPW/RZlM5LbV0v76TH56nhAAAAAAD9////AUBCDwAAAAAAGXapFGLpB7FcvyfVQlOZ6/bw+1DruI8YiKwAAAAAAAAA",
"error": null,
"id": "test"
}
createpsbt
Creates a transaction in the Partially Signed Transaction format.
Implements the Creator role.
createpsbt [{"txid":"hex","vout":n,"sequence":n},...] [{"address":amount},{"data":"hex"},...] ( locktime replaceable )
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):-
<inputs>(json array; required): the json objects.[{ (json object)"txid": "hex", (string, required) The transaction id"vout": n, (numeric, required) The output number"sequence": n, (numeric, optional, default=depends on the value of the 'replaceable' and 'locktime' arguments) The sequence number},...] -
<outputs>(json array; required): the outputs (key-value pairs), where none of the keys are duplicated. That is, each address can only appear once and there can only be one ‘data’ object. For compatibility reasons, a dictionary, which holds the key-value pairs directly, is also accepted as second parameter.[{ (json object)"address": amount, (numeric or string, required) A key-value pair. The key (string) is the bitcoin address, the value (float or string) is the amount in BTC},{ (json object)"data": "hex", (string, required) A key-value pair. The key must be "data", the value is hex-encoded data},...] -
<locktime>(numeric; optional; default=0): raw locktime. Non-0 value also locktime-activates inputs. -
<replaceable>(boolean; optional; default=false): marks this transaction as BIP125 replaceable. Allows this transaction to be replaced by a transaction with higher fees. If provided, it is an error if explicit sequence numbers are incompatible.
-
Returns
The resulting raw transaction (base64-encoded string).
Request example
curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "createpsbt",
"params": [[{"txid":"e1a9e7c7a4ef2f5d6d4bce9459f45bcff4a71fd6fcb2d42b2a14d6ed75e4bf32","vout":0}],[{"data":"00010203"}]]
}'
Response example
{
"result": "cHNidP8BAEICAAAAATK/5HXt1hQqK9Sy/NYfp/TPW/RZlM5LbV0v76TH56nhAAAAAAD9////AQAAAAAAAAAABmoEAAECAwAAAAAAAAA=",
"error": null,
"id": "test"
}
createrawtransaction
Creates a transaction spending the given inputs and creating new outputs.
Outputs can be addresses or data.
Returns hex-encoded raw transaction.
Note that the transaction’s inputs are not signed, and it is not stored in the wallet or transmitted to the network.
createrawtransaction [{"txid":"hex","vout":n,"sequence":n},...] [{"address":amount},{"data":"hex"},...] ( locktime replaceable )
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):-
<inputs>(json array; required): the inputs.[{ (json object)"txid": "hex", (string, required) The transaction id"vout": n, (numeric, required) The output number"sequence": n, (numeric, optional, default=depends on the value of the 'replaceable' and 'locktime' arguments) The sequence number},...] -
<outputs>(json array; required): the outputs (key-value pairs), where none of the keys are duplicated. That is, each address can only appear once and there can only be one ‘data’ object. For compatibility reasons, a dictionary, which holds the key-value pairs directly, is also accepted as second parameter.[{ (json object)"address": amount, (numeric or string, required) A key-value pair. The key (string) is the bitcoin address, the value (float or string) is the amount in BTC},{ (json object)"data": "hex", (string, required) A key-value pair. The key must be "data", the value is hex-encoded data},...] -
<locktime>(numeric; optional; default=0): raw locktime. Non-0 value also locktime-activates inputs. -
<replaceable>(boolean; optional; default=false): marks this transaction as BIP125-replaceable. Allows this transaction to be replaced by a transaction with higher fees. If provided, it is an error if explicit sequence numbers are incompatible.
-
Returns
A hex string of the transaction.
Request example
curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "hww",
"method": "createrawtransaction",
"params": [[{"txid":"e1a9e7c7a4ef2f5d6d4bce9459f45bcff4a71fd6fcb2d42b2a14d6ed75e4bf32","vout":0}], [{"1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa":0.01}]]
}'
Response example
{
"result": "020000000132bfe475edd6142a2bd4b2fcd61fa7f4cf5bf45994ce4b6d5d2fefa4c7e7a9e10000000000fdffffff0140420f00000000001976a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac00000000",
"error": null,
"id": "hww"
}
decodepsbt
Returns a JSON object representing the serialized, base64-encoded partially signed Bitcoin transaction.
decodepsbt "psbt"
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):<psbt>(string; required): the PSBT base64 string.
Returns
{ (json object)
"tx" : { (json object) The decoded network-serialized unsigned transaction.
... The layout is the same as the output of decoderawtransaction.
},
"unknown" : { (json object) The unknown global fields
"key" : "hex", (string) (key-value pair) An unknown key-value pair
...
},
"inputs" : [ (json array)
{ (json object)
"non_witness_utxo" : { (json object, optional) Decoded network transaction for non-witness UTXOs
...
},
"witness_utxo" : { (json object, optional) Transaction output for witness UTXOs
"amount" : n, (numeric) The value in BTC
"scriptPubKey" : { (json object)
"asm" : "str", (string) The asm
"hex" : "hex", (string) The hex
"type" : "str", (string) The type, eg 'pubkeyhash'
"address" : "str" (string) Bitcoin address if there is one
}
},
"partial_signatures" : { (json object, optional)
"pubkey" : "str", (string) The public key and signature that corresponds to it.
...
},
"sighash" : "str", (string, optional) The sighash type to be used
"redeem_script" : { (json object, optional)
"asm" : "str", (string) The asm
"hex" : "hex", (string) The hex
"type" : "str" (string) The type, eg 'pubkeyhash'
},
"witness_script" : { (json object, optional)
"asm" : "str", (string) The asm
"hex" : "hex", (string) The hex
"type" : "str" (string) The type, eg 'pubkeyhash'
},
"bip32_derivs" : [ (json array, optional)
{ (json object, optional) The public key with the derivation path as the value.
"master_fingerprint" : "str", (string) The fingerprint of the master key
"path" : "str" (string) The path
},
...
],
"final_scriptsig" : { (json object, optional)
"asm" : "str", (string) The asm
"hex" : "str" (string) The hex
},
"final_scriptwitness" : [ (json array)
"hex", (string) hex-encoded witness data (if any)
...
],
"unknown" : { (json object) The unknown global fields
"key" : "hex", (string) (key-value pair) An unknown key-value pair
...
}
},
...
],
"outputs" : [ (json array)
{ (json object)
"redeem_script" : { (json object, optional)
"asm" : "str", (string) The asm
"hex" : "hex", (string) The hex
"type" : "str" (string) The type, eg 'pubkeyhash'
},
"witness_script" : { (json object, optional)
"asm" : "str", (string) The asm
"hex" : "hex", (string) The hex
"type" : "str" (string) The type, eg 'pubkeyhash'
},
"bip32_derivs" : [ (json array, optional)
{ (json object)
"pubkey" : "str", (string) The public key this path corresponds to
"master_fingerprint" : "str", (string) The fingerprint of the master key
"path" : "str" (string) The path
},
...
],
"unknown" : { (json object) The unknown global fields
"key" : "hex", (string) (key-value pair) An unknown key-value pair
...
}
},
...
],
"fee" : n (numeric, optional) The transaction fee paid if all UTXOs slots in the PSBT have been filled.
}
Request example
curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "decodepsbt",
"params": ["cHNidP8BAEICAAAAATK/5HXt1hQqK9Sy/NYfp/TPW/RZlM5LbV0v76TH56nhAAAAAAD9////AQAAAAAAAAAABmoEAAECAwAAAAAAAAA="]
}'
Response example
{
"result": {
"tx": {
"txid": "ad0f4833625ac33a57251e4c7d43fa29ed6f0b4b0276beed9977b6f84bfe58b4",
"hash": "ad0f4833625ac33a57251e4c7d43fa29ed6f0b4b0276beed9977b6f84bfe58b4",
"version": 2,
"size": 66,
"vsize": 66,
"weight": 264,
"locktime": 0,
"vin": [
{
"txid": "e1a9e7c7a4ef2f5d6d4bce9459f45bcff4a71fd6fcb2d42b2a14d6ed75e4bf32",
"vout": 0,
"scriptSig": {
"asm": "",
"hex": ""
},
"sequence": 4294967293
}
],
"vout": [
{
"value": 0,
"n": 0,
"scriptPubKey": {
"asm": "OP_RETURN 50462976",
"desc": "raw(6a0400010203)#6scht25q",
"hex": "6a0400010203",
"type": "nulldata"
}
}
]
},
"global_xpubs": [],
"psbt_version": 0,
"proprietary": [],
"unknown": {},
"inputs": [
{}
],
"outputs": [
{}
]
},
"error": null,
"id": "test"
}
decoderawtransaction
Returns a JSON object representing the serialized, hex-encoded transaction.
decoderawtransaction "hexstring" ( iswitness )
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):<hexstring>(string; required): the transaction hex string.<iswitness>(boolean; optional; default=depends on heuristic tests): whether the transaction hex is a serialized witness transaction. Ifiswitnessis not present, heuristic tests will be used in decoding. If true, only witness deserialization will be tried. If false, only non-witness deserialization will be tried. This boolean should reflect whether the transaction has inputs (e.g. fully valid, or on-chain transactions), if known by the caller.
Returns
{ (json object)
"txid" : "hex", (string) The transaction id
"hash" : "hex", (string) The transaction hash (differs from txid for witness transactions)
"size" : n, (numeric) The 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" : xxx, (numeric) The lock time
"vin" : [ (json array)
{ (json object)
"txid" : "hex", (string) The transaction id
"vout" : n, (numeric) The output number
"scriptSig" : { (json object) The script
"asm" : "str", (string) asm
"hex" : "hex" (string) hex
},
"txinwitness" : [ (json array)
"hex", (string) hex-encoded witness data (if any)
...
],
"sequence" : n (numeric) The script sequence number
},
...
],
"vout" : [ (json array)
{ (json object)
"value" : n, (numeric) The value in BTC
"n" : n, (numeric) index
"scriptPubKey" : { (json object)
"asm" : "str", (string) the asm
"hex" : "hex", (string) the hex
"reqSigs" : n, (numeric) The required sigs
"type" : "str", (string) The type, eg 'pubkeyhash'
"addresses" : [ (json array)
"str", (string) bitcoin address
...
]
}
},
...
]
}
Request example
curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "decoderawtransaction",
"params": ["02000000017e7c9f1b7eb7d7a48028a705a23f30ae9712a1b9c229aa57f948155f1d99f6b60000000000fdffffff0140420f00000000001976a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac00000000"]
}'
Response example
{
"result": {
"txid": "af71499460ee644f623f51d023dc837f3e2ae5dd6995ab872931fdb0cff2c2ee",
"hash": "af71499460ee644f623f51d023dc837f3e2ae5dd6995ab872931fdb0cff2c2ee",
"version": 2,
"size": 85,
"vsize": 85,
"weight": 340,
"locktime": 0,
"vin": [
{
"txid": "b6f6991d5f1548f957aa29c2b9a11297ae303fa205a72880a4d7b77e1b9f7c7e",
"vout": 0,
"scriptSig": {
"asm": "",
"hex": ""
},
"sequence": 4294967293
}
],
"vout": [
{
"value": 0.01,
"n": 0,
"scriptPubKey": {
"asm": "OP_DUP OP_HASH160 62e907b15cbf27d5425399ebf6f0fb50ebb88f18 OP_EQUALVERIFY OP_CHECKSIG",
"desc": "addr(1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa)#632p52jr",
"hex": "76a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac",
"address": "1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa",
"type": "pubkeyhash"
}
}
]
},
"error": null,
"id": "test"
}
decodescript
Decodes a hex-encoded script.
decodescript "hexstring"
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):<hexstring>(string; required): the hex-encoded script.
Returns
{ (json object)
"asm" : "str", (string) Script public key
"type" : "str", (string) The output type (e.g. nonstandard, pubkey, pubkeyhash, scripthash, multisig, nulldata, witness_v0_scripthash, witness_v0_keyhash, witness_v1_taproot, witness_unknown)
"reqSigs" : n, (numeric) The required signatures
"addresses" : [ (json array)
"str", (string) bitcoin address
...
],
"p2sh" : "str", (string) address of P2SH script wrapping this redeem script (not returned if the script is already a P2SH)
"segwit" : { (json object) Result of a witness script public key wrapping this redeem script (not returned if the script is a P2SH or witness)
"asm" : "str", (string) String representation of the script public key
"hex" : "hex", (string) Hex string of the script public key
"type" : "str", (string) The type of the script public key (e.g. witness_v0_keyhash or witness_v0_scripthash)
"reqSigs" : n, (numeric) The required signatures (always 1)
"addresses" : [ (json array) (always length 1)
"str", (string) segwit address
...
],
"p2sh-segwit" : "str" (string) address of the P2SH script wrapping this witness redeem script
}
}
Request example
curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "decodescript",
"params": ["76a91489abcdefabbaabbaabbaabbaabbaabbaabbaabba88ac"]
}'
Response example
{
"result": {
"asm": "OP_DUP OP_HASH160 89abcdefabbaabbaabbaabbaabbaabbaabbaabba OP_EQUALVERIFY OP_CHECKSIG",
"desc": "addr(1DYwPTpZuLjY2qApmJdHaSAuWRvEF5skCN)#kh26y3vv",
"address": "1DYwPTpZuLjY2qApmJdHaSAuWRvEF5skCN",
"type": "pubkeyhash",
"p2sh": "3F6i6kwkevjR7AsAd4te2YB2zZyASEm1HM",
"segwit": {
"asm": "0 89abcdefabbaabbaabbaabbaabbaabbaabbaabba",
"desc": "addr(bc1q3x4ummath24m42a64wa2hw4th24m42a6rul9r7)#fpmsztnh",
"hex": "001489abcdefabbaabbaabbaabbaabbaabbaabbaabba",
"address": "bc1q3x4ummath24m42a64wa2hw4th24m42a6rul9r7",
"type": "witness_v0_keyhash",
"p2sh-segwit": "37PDvpSnXXNRppuGZxa4CvqdfeNh9j6DtE"
}
},
"error": null,
"id": "test"
}
finalizepsbt
Finalizes the inputs of a PSBT.
Finalize the inputs of a PSBT. If the transaction is fully signed, it will produce a network serialized transaction which can be broadcast with sendrawtransaction. Otherwise, a PSBT will be created which has the final_scriptSig and final_scriptWitness fields filled for inputs that are complete.
Implements the Finalizer and Extractor roles.
finalizepsbt "psbt" ( extract )
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):<psbt>(string; required): a base64 string of a PSBT.<extract>(boolean; optional; default=true):trueand the transaction is complete, extract and return the complete transaction in normal network serialization instead of the PSBT.
Returns
{ (json object)
"psbt" : "str", (string) The base64-encoded partially signed transaction if not extracted
"hex" : "hex", (string) The hex-encoded network transaction if extracted
"complete" : true|false (boolean) If the transaction has a complete set of signatures
}
Request example
curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "finalizepsbt",
"params": ["cHNidP8BAFUCAAAAATK/5HXt1hQqK9Sy/NYfp/TPW/RZlM5LbV0v76TH56nhAAAAAAD9////AUBCDwAAAAAAGXapFGLpB7FcvyfVQlOZ6/bw+1DruI8YiKwAAAAAAAAA"]
}'
Response example
{
"result": {
"psbt": "cHNidP8BAFUCAAAAATK/5HXt1hQqK9Sy/NYfp/TPW/RZlM5LbV0v76TH56nhAAAAAAD9////AUBCDwAAAAAAGXapFGLpB7FcvyfVQlOZ6/bw+1DruI8YiKwAAAAAAAAA",
"complete": false
},
"error": null,
"id": "test"
}
getrawtransaction
Returns the raw transaction data.
getrawtransaction "txid" ( verbose "blockhash" )
By default, this function only works for mempool transactions. When called with a blockhash argument, getrawtransaction will return the transaction if the specified block is available and the transaction is found in that block. When called without a blockhash argument, getrawtransaction will return the transaction if it is in the mempool, or if -txindex is enabled and the transaction is in a block in the blockchain.
Hint: Use gettransaction for wallet transactions.
If verbose is true, returns an Object with information about txid.
If verbose is false or omitted, returns a string that is serialized, hex-encoded data for txid.
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>(string; required): the transaction ID.<verbose>(boolean; optional; default=false): iffalse, return a string, otherwise return a json object.<blockhash>(string; optional): the block in which to look for the transaction.
Returns
Verbose=false:
The serialized, hex-encoded data for txid.
Verbose=true:
{ (json object)
"in_active_chain" : true|false, (boolean) Whether specified block is in the active chain or not (only present with explicit "blockhash" argument)
"hex" : "hex", (string) The serialized, hex-encoded data for 'txid'
"txid" : "hex", (string) The transaction id (same as provided)
"hash" : "hex", (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" : xxx, (numeric) The lock time
"vin" : [ (json array)
{ (json object)
"txid" : "hex", (string) The transaction id
"vout" : n, (numeric) The output number
"scriptSig" : { (json object) The script
"asm" : "str", (string) asm
"hex" : "hex" (string) hex
},
"sequence" : n, (numeric) The script sequence number
"txinwitness" : [ (json array)
"hex", (string) hex-encoded witness data (if any)
...
]
},
...
],
"vout" : [ (json array)
{ (json object)
"value" : n, (numeric) The value in BTC
"n" : n, (numeric) index
"scriptPubKey" : { (json object)
"asm" : "str", (string) the asm
"hex" : "str", (string) the hex
"reqSigs" : n, (numeric) The required sigs
"type" : "str", (string) The type, eg 'pubkeyhash'
"addresses" : [ (json array)
"str", (string) bitcoin address
...
]
}
},
...
],
"blockhash" : "hex", (string) the block hash
"confirmations" : n, (numeric) The confirmations
"blocktime" : xxx, (numeric) The block time expressed in UNIX epoch time
"time" : n (numeric) Same as "blocktime"
}
Request example
curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "getrawtransaction",
"params": ["c7f32887779200fec23a0f4ebe73bed003f9ab8a46c2b549320c3c5cb78c7dc9", false, "000000000000000000034e30310c8bf30133e41ae3ae189f987e509901409bf7"]
}'
Response example
{
"result": "010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff560327df0c194d696e656420627920416e74506f6f6c20d1001e027fbb47f4fabe6d6de0c279796c6962fedcf285c9d73b2db2bdbf613053c23bde86fbfd601dcb857f10000000000000000000a0a91100000000000000ffffffff05220200000000000017a91442402a28dd61f2718a4b27ae72a4791d5bbdade787e380d0130000000017a9145249bdf2c131d43995cff42e8feee293f79297a8870000000000000000266a24aa21a9edbec170280a56f035b0341dbbddd94bb6e7980831c83800833367122d7aa839dc00000000000000002f6a2d434f524501a37cf4faa0758b26dca666f3e36d42fa15cc01064e3ecda72cb7961caa4b541b1e322bcfe0b5a03000000000000000002b6a2952534b424c4f434b3a4a651ea38b372994e3ba5f22984412606c1f031ea133168998896e280060d9d20120000000000000000000000000000000000000000000000000000000000000000000000000",
"error": null,
"id": "test"
}
joinpsbts
Joins multiple distinct PSBTs with different inputs and outputs into one PSBT.
Joins multiple distinct PSBTs with different inputs and outputs into one PSBT with inputs and outputs from all of the PSBTs. No input in any of the PSBTs can be in more than one of the PSBTs.
joinpsbts ["psbt",...]
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):-
<txs>(array of strings; required): the base64 strings of partially signed transactions.["psbt", (string, required) A base64 string of a PSBT...]
-
Returns
The base64-encoded partially signed transaction.
Request example
curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "joinpsbts",
"params": ["my-spbt1", "my-spbt2", "my-spbt3"]
}'
sendrawtransaction
Submits a raw transaction (serialized, hex-encoded) to local node and network.
Note that the transaction will be sent unconditionally to all peers, so using this for manual rebroadcast may degrade privacy by leaking the transaction’s origin, as nodes will normally not rebroadcast non-wallet transactions already in their mempool.
Also see createrawtransaction and signrawtransactionwithkey calls.
sendrawtransaction "hexstring" ( maxfeerate )
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):<hexstring>(string; required): the hex string of the raw transaction.<maxfeerate>(numeric/string; optional; default=0.10): rejects transactions whose fee rate is higher than the specified value, expressed in BTC/kB. Set to 0 to accept any fee rate.
Returns
The transaction hash in hex.
Request example
Create a transaction:
curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "createrawtransaction",
"params": [[{"txid":"b6f6991d5f1548f957aa29c2b9a11297ae303fa205a72880a4d7b77e1b9f7c7e","vout":0}], {"1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa":0.01}]
}'
Sign the transaction, and get back the hex:
curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "signrawtransactionwithwallet",
"params": ["0200000001b6f6991d5f1548f957aa29c2b9a11297ae303fa205a72880a4d7b77e1b9f7c7e0000000000ffffffff0100f2052a010000001976a91489abcdefabbaabbaabbaabbaabbaabbaabbaabba88ac00000000"]
}'
Send the transaction (signed hex):
curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "sendrawtransaction",
"params": ["0200000001b6f6991d5f1548f957aa29c2b9a11297ae303fa205a72880a4d7b77e1b9f7c7e010000006a47304402203b8e51e8ee7a9f23f7c7ea3a73a9b7d9fda7914f7f7d433c9a9e6efad0706e9f022073c405f2beed367d9
testmempoolaccept
Returns result of mempool acceptance tests.
Returns result of mempool acceptance tests indicating if raw transaction (serialized, hex-encoded) would be accepted by mempool.
This checks if the transaction violates the consensus or policy rules.
See sendrawtransaction call.
testmempoolaccept ["rawtx",...] ( maxfeerate )
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):-
<rawtxs>(array of strings; required): an array of hex strings of raw transactions.["rawtx", (string)...] -
<maxfeerate>(numeric/string; optional; default=0.10): rejects transactions whose fee rate is higher than the specified value, expressed in BTC/kB.
-
Returns
[ (json array) The result of the mempool acceptance test for each raw transaction in the input array.
Length is exactly one for now.
{ (json object)
"txid" : "hex", (string) The transaction hash in hex
"allowed" : true|false, (boolean) If the mempool allows this tx to be inserted
"vsize" : n, (numeric) Virtual transaction size as defined in BIP 141. This is different from actual serialized size for witness transactions as witness data is discounted (only present when 'allowed' is true)
"fees" : { (json object) Transaction fees (only present if 'allowed' is true)
"base" : n (numeric) transaction fee in BTC
},
"reject-reason" : "str" (string) Rejection string (only present when 'allowed' is false)
},
...
]
Request example
Create a transaction:
curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "createrawtransaction",
"params": [[{"txid":"b6f6991d5f1548f957aa29c2b9a11297ae303fa205a72880a4d7b77e1b9f7c7e","vout":0}], {"1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa":0.01}]
}'
Sign the transaction, and get back the hex:
curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "signrawtransactionwithwallet",
"params": ["0200000001b6f6991d5f1548f957aa29c2b9a11297ae303fa205a72880a4d7b77e1b9f7c7e0000000000ffffffff0100f2052a010000001976a91489abcdefabbaabbaabbaabbaabbaabbaabbaabba88ac00000000"]
}'
Test acceptance of the transaction (signed hex):
curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "testmempoolaccept",
"params": [["0200000001b6f6991d5f1548f957aa29c2b9a11297ae303fa205a72880a4d7b77e1b9f7c7e010000006a47304402203b8e51e8ee7a9f23f7c7ea3a73a9b7d9fda7914f7f7d433c9a9e6efad0706e9f022073c405f2beed367d9f7ee5e8e6a4e5e5c595cf1fa2b3b5dc74db9b2a36d4e7ec012102f3b5c0e7322d3e72d40c7f6b3fd8b1ab3141574a63eefa9a098c4b0be1dbb5e4ffffffff0100f2052a010000001976a91489abcdefabbaabbaabbaabbaabbaabbaabbaabba88ac00000000"]]
}'
Reponse example
{
"result": [
{
"txid": "077e6ae456a9d84b4bc85aa782121e8b725031178595326d4df078927a66e998",
"wtxid": "077e6ae456a9d84b4bc85aa782121e8b725031178595326d4df078927a66e998",
"allowed": false,
"reject-reason": "missing-inputs"
}
],
"error": null,
"id": "test"
}
utxoupdatepsbt
Updates all segwit inputs and outputs in a PSBT with data from output descriptors, the UTXO set, or the mempool.
utxoupdatepsbt "psbt" ( ["",{"desc":"str","range":n or [n,n]},...] )
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):-
<psbt>(string; required): a base64 string of a PSBT. -
<descriptors>(array; optional): an array of either strings or objects.["", (string) An output descriptor{ (json object) An object with an output descriptor and extra information"desc": "str", (string, required) An output descriptor"range": n or [n,n], (numeric or array, optional, default=1000) Up to what index HD chains should be explored (either end or [begin,end])},...]
-
Returns
The base64-encoded partially signed transaction with inputs updated.
Request example
curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "utxoupdatepsbt",
"params": ["cHNidP8BAFUCAAAAATK/5HXt1hQqK9Sy/NYfp/TPW/RZlM5LbV0v76TH56nhAAAAAAD9////AUBCDwAAAAAAGXapFGLpB7FcvyfVQlOZ6/bw+1DruI8YiKwAAAAAAAAA"]
}'
Response example
{
"result": "cHNidP8BAFUCAAAAATK/5HXt1hQqK9Sy/NYfp/TPW/RZlM5LbV0v76TH56nhAAAAAAD9////AUBCDwAAAAAAGXapFGLpB7FcvyfVQlOZ6/bw+1DruI8YiKwAAAAAAAAA",
"error": null,
"id": "test"
}
Util RPCs
estimatesmartfee
Estimates the approximate fee.
Estimates the approximate fee per kilobyte needed for a transaction to begin confirmation within conf_target blocks if possible and return the number of blocks for which the estimate is valid. Uses virtual transaction size as defined in BIP 141 (witness data is discounted).
estimatesmartfee conf_target ( "estimate_mode" )
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):<conf_target>(numeric; required): confirmation target in blocks (1 - 1008).<estimate_mode>(string; optional; default=CONSERVATIVE): the fee estimate mode. Whether to return a more conservative estimate which also satisfies a longer history. A conservative estimate potentially returns a higher feerate and is more likely to be sufficient for the desired target, but is not as responsive to short term drops in the prevailing fee market. Must be one of: “UNSET” “ECONOMICAL” “CONSERVATIVE”.
Returns
{ (json object)
"feerate" : n, (numeric, optional) estimate fee rate in BTC/kB (only present if no errors were encountered)
"errors" : [ (json array, optional) Errors encountered during processing (if there are any)
"str", (string) error
...
],
"blocks" : n (numeric) block number where estimate was found
The request target will be clamped between 2 and the highest target
fee estimation is able to return based on how long it has been running.
An error is returned if not enough transactions and blocks
have been observed to make an estimate for any number of blocks.
}
Request example
curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "estimatesmartfee",
"params": [6]
}'
Response example
{
"result": {
"feerate": 0.00012296,
"blocks": 6
},
"error": null,
"id": "test"
}
getindexinfo
Returns the status of one or all available indices currently running in the node.
getindexinfo ( "index_name" )
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):<txindex>(string; optional): filters results for an index with a specific name.
Returns
{ (json object)
"name" : { (json object) The name of the index
"synced" : true|false, (boolean) Whether the index is synced or not
"best_block_height" : n (numeric) The block height to which the index is synced
}
}
Request example
curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "getindexinfo",
"params": ["txindex"]
}'
validateaddress
Returns information about the given bitcoin address.
validateaddress "address"
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):<address>(string; required): the Bitcoin address to validate.
Returns
{ (json object)
"isvalid" : true|false, (boolean) If the address is valid or not. If not, this is the only property returned.
"address" : "str", (string) The bitcoin address validated
"scriptPubKey" : "hex", (string) The hex-encoded scriptPubKey generated by the address
"isscript" : true|false, (boolean) If the key is a script
"iswitness" : true|false, (boolean) If the address is a witness address
"witness_version" : n, (numeric, optional) The version number of the witness program
"witness_program" : "hex" (string, optional) The hex value of the witness program
}
Request example
curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "validateaddress",
"params": ["bc1qw4e2dl3pfw6nzxrzpghrtnpx7y8kyj7vg09qlh"]
}'
Response example
{
"result": {
"isvalid": false,
"error_locations": [
35,
36
],
"error": "Invalid Bech32 checksum"
},
"error": null,
"id": "test"
}
verifymessage
Verifies a signed message.
verifymessage "address" "signature" "message"
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):<address>(string; required): the Bitcoin address to use for the signature.<signature>(string; required): the signature provided by the signer in base 64 encoding (seesignmessage).<message>(string; required): the message that was signed.
Returns
If the signature is verified or not.
Request example
curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "verifymessage",
"params": ["1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX", "signature", "my message"]
}'
Wallet RPCs
The wallet RPCs are only available if Bitcoin Core was built with wallet support, which is the default.
getaddressinfo
Returns information about the given Bitcoin address.
Some information will only be present if the address is in the active wallet.
getaddressinfo "address"
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):<address>(string; required): the Bitcoin address for which to get information.
Returns
{ (json object)
"address" : "str", (string) The bitcoin address validated.
"scriptPubKey" : "hex", (string) The hex-encoded scriptPubKey generated by the address.
"ismine" : true|false, (boolean) If the address is yours.
"iswatchonly" : true|false, (boolean) If the address is watchonly.
"solvable" : true|false, (boolean) If we know how to spend coins sent to this address, ignoring the possible lack of private keys.
"desc" : "str", (string, optional) A descriptor for spending coins sent to this address (only when solvable).
"isscript" : true|false, (boolean) If the key is a script.
"ischange" : true|false, (boolean) If the address was used for change output.
"iswitness" : true|false, (boolean) If the address is a witness address.
"witness_version" : n, (numeric, optional) The version number of the witness program.
"witness_program" : "hex", (string, optional) The hex value of the witness program.
"script" : "str", (string, optional) The output script type. Only if isscript is true and the redeemscript is known. Possible
types: nonstandard, pubkey, pubkeyhash, scripthash, multisig, nulldata, witness_v0_keyhash,
witness_v0_scripthash, witness_unknown.
"hex" : "hex", (string, optional) The redeemscript for the p2sh address.
"pubkeys" : [ (json array, optional) Array of pubkeys associated with the known redeemscript (only if script is multisig).
"str", (string)
...
],
"sigsrequired" : n, (numeric, optional) The number of signatures required to spend multisig output (only if script is multisig).
"pubkey" : "hex", (string, optional) The hex value of the raw public key for single-key addresses (possibly embedded in P2SH or P2WSH).
"embedded" : { (json object, optional) Information about the address embedded in P2SH or P2WSH, if relevant and known.
... Includes all getaddressinfo output fields for the embedded address, excluding metadata (timestamp, hdkeypath, hdseedid)
and relation to the wallet (ismine, iswatchonly).
},
"iscompressed" : true|false, (boolean, optional) If the pubkey is compressed.
"timestamp" : xxx, (numeric, optional) The creation time of the key, if available, expressed in UNIX epoch time.
"hdkeypath" : "str", (string, optional) The HD keypath, if the key is HD and available.
"hdseedid" : "hex", (string, optional) The Hash160 of the HD seed.
"hdmasterfingerprint" : "hex", (string, optional) The fingerprint of the master key.
"labels" : [ (json array) Array of labels associated with the address. Currently limited to one label but returned as an array to keep the API stable if multiple labels are enabled in the future.
"str", (string) Label name (defaults to "").
...
]
}
Request example
curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "getaddressinfo",
"params": ["bc1q09vm5lfy0j5reeulh4x5752q25uqqvz34hufdl"]
}'