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 — Blockchain RPCs (2/3)

API reference for Bitcoin. All methods ->

Part 2 of 3: 1 · 2 · 3

Blockchain RPCs

getchaintxstats

Computes statistics about the total number and rate of transactions in the chain.

getchaintxstats ( nblocks "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):

    • <nblocks> (numeric; optional; default=one month): size of the window in number of blocks
    • <blockhash> (string; optional; default=chain tip): the hash of the block that ends the window.

Returns

{ (json object)
"time" : xxx, (numeric) The timestamp for the final block in the window, expressed in UNIX epoch time
"txcount" : n, (numeric) The total number of transactions in the chain up to that point
"window_final_block_hash" : "hex", (string) The hash of the final block in the window
"window_final_block_height" : n, (numeric) The height of the final block in the window.
"window_block_count" : n, (numeric) Size of the window in number of blocks
"window_tx_count" : n, (numeric) The number of transactions in the window. Only returned if "window_block_count" is > 0
"window_interval" : n, (numeric) The elapsed time in the window in seconds. Only returned if "window_block_count" is > 0
"txrate" : n (numeric) The average rate of transactions per second in the window. Only returned if "window_interval" is > 0
}

Request example

curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "getchaintxstats",
"params": [2016]
}'

Response example

{
"result": {
"time": 1715767659,
"txcount": 1005147385,
"window_final_block_hash": "00000000000000000001f0d113bbcef2c1f52882bf8044a7df5299d364216734",
"window_final_block_height": 843553,
"window_block_count": 2016,
"window_tx_count": 7940938,
"window_interval": 1269305,
"txrate": 6.256130717203509
},
"error": null,
"id": "test"
}

getdifficulty

Returns the proof-of-work difficulty as a multiple of the minimum difficulty.

getdifficulty

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): none.

Returns

The proof-of-work difficulty as a multiple of the minimum difficulty.

Request example

curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "getdifficulty",
"params": []
}'

Response example

{
"result": 83148355189239.77,
"error": null,
"id": "test"
}

getmempoolancestors

If txid is in the mempool, returns all in-mempool ancestors.

getmempoolancestors "txid" ( verbose )

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 (must be in mempool).
    • <verbose> (boolean; optional; default=false): true for a json object, false for array of transaction ids.

Returns

Verbose=false:

[ (json array)
"hex", (string) The transaction id of an in-mempool ancestor transaction
...
]

Verbose=true:

{ (json object)
"transactionid" : { (json object)
"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.
"weight" : n, (numeric) transaction weight as defined in BIP 141.
"fee" : n, (numeric) transaction fee in BTC (DEPRECATED)
"modifiedfee" : n, (numeric) transaction fee with fee deltas used for mining priority (DEPRECATED)
"time" : xxx, (numeric) local time transaction entered pool in seconds since 1 Jan 1970 GMT
"height" : n, (numeric) block height when transaction entered pool
"descendantcount" : n, (numeric) number of in-mempool descendant transactions (including this one)
"descendantsize" : n, (numeric) virtual transaction size of in-mempool descendants (including this one)
"descendantfees" : n, (numeric) modified fees (see above) of in-mempool descendants (including this one) (DEPRECATED)
"ancestorcount" : n, (numeric) number of in-mempool ancestor transactions (including this one)
"ancestorsize" : n, (numeric) virtual transaction size of in-mempool ancestors (including this one)
"ancestorfees" : n, (numeric) modified fees (see above) of in-mempool ancestors (including this one) (DEPRECATED)
"wtxid" : "hex", (string) hash of serialized transaction, including witness data
"fees" : { (json object)
"base" : n, (numeric) transaction fee in BTC
"modified" : n, (numeric) transaction fee with fee deltas used for mining priority in BTC
"ancestor" : n, (numeric) modified fees (see above) of in-mempool ancestors (including this one) in BTC
"descendant" : n (numeric) modified fees (see above) of in-mempool descendants (including this one) in BTC
},
"depends" : [ (json array) unconfirmed transactions used as inputs for this transaction
"hex", (string) parent transaction id
...
],
"spentby" : [ (json array) unconfirmed transactions spending outputs from this transaction
"hex", (string) child transaction id
...
],
"bip125-replaceable" : true|false, (boolean) Whether this transaction could be replaced due to BIP125 (replace-by-fee)
"unbroadcast" : true|false (boolean) Whether this transaction is currently unbroadcast (initial broadcast not yet acknowledged by any peers)
},
...
}

Request example

curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "getmempoolancestors",
"params": ["mytxid"]
}'

getmempooldescendants

If txid is in the mempool, returns all in-mempool descendants.

getmempooldescendants "txid" ( verbose )

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 (must be in mempool).
    • <verbose> (boolean; optional; default=false): true for a json object, false for array of transaction ids.

Returns

Verbose=false:

[ (json array)
"hex", (string) The transaction id of an in-mempool descendant transaction
...
]

Verbose=true:

{ (json object)
"transactionid" : { (json object)
"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.
"weight" : n, (numeric) transaction weight as defined in BIP 141.
"fee" : n, (numeric) transaction fee in BTC (DEPRECATED)
"modifiedfee" : n, (numeric) transaction fee with fee deltas used for mining priority (DEPRECATED)
"time" : xxx, (numeric) local time transaction entered pool in seconds since 1 Jan 1970 GMT
"height" : n, (numeric) block height when transaction entered pool
"descendantcount" : n, (numeric) number of in-mempool descendant transactions (including this one)
"descendantsize" : n, (numeric) virtual transaction size of in-mempool descendants (including this one)
"descendantfees" : n, (numeric) modified fees (see above) of in-mempool descendants (including this one) (DEPRECATED)
"ancestorcount" : n, (numeric) number of in-mempool ancestor transactions (including this one)
"ancestorsize" : n, (numeric) virtual transaction size of in-mempool ancestors (including this one)
"ancestorfees" : n, (numeric) modified fees (see above) of in-mempool ancestors (including this one) (DEPRECATED)
"wtxid" : "hex", (string) hash of serialized transaction, including witness data
"fees" : { (json object)
"base" : n, (numeric) transaction fee in BTC
"modified" : n, (numeric) transaction fee with fee deltas used for mining priority in BTC
"ancestor" : n, (numeric) modified fees (see above) of in-mempool ancestors (including this one) in BTC
"descendant" : n (numeric) modified fees (see above) of in-mempool descendants (including this one) in BTC
},
"depends" : [ (json array) unconfirmed transactions used as inputs for this transaction
"hex", (string) parent transaction id
...
],
"spentby" : [ (json array) unconfirmed transactions spending outputs from this transaction
"hex", (string) child transaction id
...
],
"bip125-replaceable" : true|false, (boolean) Whether this transaction could be replaced due to BIP125 (replace-by-fee)
"unbroadcast" : true|false (boolean) Whether this transaction is currently unbroadcast (initial broadcast not yet acknowledged by any peers)
},
...
}

Request example

curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "getmempooldescendants",
"params": ["mytxid"]
}'

getmempoolentry

Returns mempool data for given transaction.

getmempoolentry "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 (must be in mempool).

Returns

{ (json object)
"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.
"weight" : n, (numeric) transaction weight as defined in BIP 141.
"fee" : n, (numeric) transaction fee in BTC (DEPRECATED)
"modifiedfee" : n, (numeric) transaction fee with fee deltas used for mining priority (DEPRECATED)
"time" : xxx, (numeric) local time transaction entered pool in seconds since 1 Jan 1970 GMT
"height" : n, (numeric) block height when transaction entered pool
"descendantcount" : n, (numeric) number of in-mempool descendant transactions (including this one)
"descendantsize" : n, (numeric) virtual transaction size of in-mempool descendants (including this one)
"descendantfees" : n, (numeric) modified fees (see above) of in-mempool descendants (including this one) (DEPRECATED)
"ancestorcount" : n, (numeric) number of in-mempool ancestor transactions (including this one)
"ancestorsize" : n, (numeric) virtual transaction size of in-mempool ancestors (including this one)
"ancestorfees" : n, (numeric) modified fees (see above) of in-mempool ancestors (including this one) (DEPRECATED)
"wtxid" : "hex", (string) hash of serialized transaction, including witness data
"fees" : { (json object)
"base" : n, (numeric) transaction fee in BTC
"modified" : n, (numeric) transaction fee with fee deltas used for mining priority in BTC
"ancestor" : n, (numeric) modified fees (see above) of in-mempool ancestors (including this one) in BTC
"descendant" : n (numeric) modified fees (see above) of in-mempool descendants (including this one) in BTC
},
"depends" : [ (json array) unconfirmed transactions used as inputs for this transaction
"hex", (string) parent transaction id
...
],
"spentby" : [ (json array) unconfirmed transactions spending outputs from this transaction
"hex", (string) child transaction id
...
],
"bip125-replaceable" : true|false, (boolean) Whether this transaction could be replaced due to BIP125 (replace-by-fee)
"unbroadcast" : true|false (boolean) Whether this transaction is currently unbroadcast (initial broadcast not yet acknowledged by any peers)
}

Request example

curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "getmempoolentry",
"params": ["mytxid"]
}'

getmempoolinfo

Returns the details on the active state of the TX memory pool.

getmempoolinfo

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): none.

Returns

{ (json object)
"loaded" : true|false, (boolean) True if the mempool is fully loaded
"size" : n, (numeric) Current tx count
"bytes" : n, (numeric) Sum of all virtual transaction sizes as defined in BIP 141. Differs from actual serialized size because witness data is discounted
"usage" : n, (numeric) Total memory usage for the mempool
"maxmempool" : n, (numeric) Maximum memory usage for the mempool
"mempoolminfee" : n, (numeric) Minimum fee rate in BTC/kB for tx to be accepted. Is the maximum of minrelaytxfee and minimum mempool fee
"minrelaytxfee" : n, (numeric) Current minimum relay fee for transactions
"unbroadcastcount" : n (numeric) Current number of transactions that haven't passed initial broadcast yet
}

Request example

curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "getmempoolinfo",
"params": []
}'

Response example

{
"result": {
"loaded": true,
"size": 57725,
"bytes": 90167011,
"usage": 294308080,
"total_fee": 7.18859673,
"maxmempool": 300000000,
"mempoolminfee": 0.00004923,
"minrelaytxfee": 0.00001,
"incrementalrelayfee": 0.00001,
"unbroadcastcount": 0,
"fullrbf": false
},
"error": null,
"id": "test"
}

getrawmempool

Returns all transaction ids in memory pool as a json array of string transaction ids.

Hint: use getmempoolentry to fetch a specific transaction from the mempool.

getrawmempool ( verbose mempool_sequence )

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):

    • <verbose> (boolean; optional; default=false): true for a json object, false for array of transaction ids.
    • <mempool_sequence> (boolean; optional; default=false): if verbose=false, returns a json object with transaction list and mempool sequence number attached.

Returns

Verbose=false:

[ (json array)
"hex", (string) The transaction id
...
]

Verbose=true:

{ (json object)
"transactionid" : { (json object)
"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.
"weight" : n, (numeric) transaction weight as defined in BIP 141.
"fee" : n, (numeric) transaction fee in BTC (DEPRECATED)
"modifiedfee" : n, (numeric) transaction fee with fee deltas used for mining priority (DEPRECATED)
"time" : xxx, (numeric) local time transaction entered pool in seconds since 1 Jan 1970 GMT
"height" : n, (numeric) block height when transaction entered pool
"descendantcount" : n, (numeric) number of in-mempool descendant transactions (including this one)
"descendantsize" : n, (numeric) virtual transaction size of in-mempool descendants (including this one)
"descendantfees" : n, (numeric) modified fees (see above) of in-mempool descendants (including this one) (DEPRECATED)
"ancestorcount" : n, (numeric) number of in-mempool ancestor transactions (including this one)
"ancestorsize" : n, (numeric) virtual transaction size of in-mempool ancestors (including this one)
"ancestorfees" : n, (numeric) modified fees (see above) of in-mempool ancestors (including this one) (DEPRECATED)
"wtxid" : "hex", (string) hash of serialized transaction, including witness data
"fees" : { (json object)
"base" : n, (numeric) transaction fee in BTC
"modified" : n, (numeric) transaction fee with fee deltas used for mining priority in BTC
"ancestor" : n, (numeric) modified fees (see above) of in-mempool ancestors (including this one) in BTC
"descendant" : n (numeric) modified fees (see above) of in-mempool descendants (including this one) in BTC
},
"depends" : [ (json array) unconfirmed transactions used as inputs for this transaction
"hex", (string) parent transaction id
...
],
"spentby" : [ (json array) unconfirmed transactions spending outputs from this transaction
"hex", (string) child transaction id
...
],
"bip125-replaceable" : true|false, (boolean) Whether this transaction could be replaced due to BIP125 (replace-by-fee)
"unbroadcast" : true|false (boolean) Whether this transaction is currently unbroadcast (initial broadcast not yet acknowledged by any peers)
},
...
}

verbose=false and mempool_sequence=true:

{ (json object)
"txids" : [ (json array)
"hex", (string) The transaction id
...
],
"mempool_sequence" : n (numeric) The mempool sequence value.
}

Request example

curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "getrawmempool",
"params": []
}'

Response example

{
"result": [
"09448e71251330ff2fab39365284df31278eee4a5102556f674f32155d5eda5b",
"703feebeac6110ec3ab941e6c2e6ef655dc303f77209a142864828e4bba7bfc9",
"587af96d47e5ff6b9690ccba02fafb07473ed70a4528ec34ab5d7bcb1cef7c2e",
"6557e364a70420a1c0d06bad1eaff11cf23ccce3714aa2f384dcc854211f69cc",
"7e42415091463558478e17e62517faace89e14a88c430e0efb9b511739c6b31d",
"9eda12a34bbf507265c21e8d6c59dbfc1a779f238db7c06e8e8160147f74cbef",
"e44938eacb53f4e8a5e61a67cd3f840c02d26ff999349c523cf36761f711fcb4",
"e3494ca0f7fea1e598a1ec090f2f50df989e6c7b36ed1815a67f4a5c1b9e441b",
"7bf20128eb9904fdf4d5dd1a7fafe9d494c52304574a3fcd88c188a83a32086f",
"ebaedb496434bbd6b218e2d5ea1cb6d948a30cabb8f41576c4f15c5e4ad34f9d",
"75f614042e2bd67ac5ee19f425830333ae0381a706afa2b4d21c6f49745b6bff",
"85a183e9e19630e77b65abbf4e50305b32d683626099f65c385f034a2e72cb75"
],
"error": null,
"id": "test"
}

gettxout

Returns details about an unspent transaction output.

gettxout "txid" n ( include_mempool )

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.
    • <n> (numeric; required): vout number.
    • <include_mempool> (boolean; optional; default=true): whether to include the mempool. Note that an unspent output that is spent in the mempool won’t appear.

Returns

{ (json object)
"bestblock" : "hex", (string) The hash of the block at the tip of the chain
"confirmations" : n, (numeric) The number of confirmations
"value" : n, (numeric) The transaction value in BTC
"scriptPubKey" : { (json object)
"asm" : "hex", (string)
"hex" : "hex", (string)
"reqSigs" : n, (numeric) Number of required signatures
"type" : "hex", (string) The type, eg pubkeyhash
"addresses" : [ (json array) array of bitcoin addresses
"str", (string) bitcoin address
...
]
},
"coinbase" : true|false (boolean) Coinbase or not
}

Request example

curl -X POST https://rpc.ankr.com/btc/YOUR_ANKR_API_KEY \
-d '{
"id": "test",
"method": "gettxout",
"params": ["txid", 1]
}'