Bitcoin — Raw transactions RPCs, Util RPCs, Wallet RPCs (1/3)
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"
}