For AI agents: an LLM-friendly Markdown version of every page is available by appending .md to its URL or by sending an Accept: text/markdown request header. The full documentation index is at https://www.ankr.com/docs/llms.txt
Skip to main content

Bitcoin — Raw transactions RPCs, Util RPCs, Wallet RPCs (2/3)

API reference for Bitcoin. All methods ->

Part 2 of 3: 1 · 2 · 3

Raw transactions RPCs

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): true and 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): if false, 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 (see signmessage).
    • <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"]
}'