
btc (Standard Bitcoin RPC)
SANDSHREW hosts a fully hosted Bitcoin node, for each supported network, and passes through JSON-RPC requests that are either namespaced with the btc_ prefix, or otherwise have no namespace, directly to the Bitcoin core JSON-RPC which will be familiar to anyone who has developed against a Bitcoin node. The Bitcoin node hosted by SANDSHREW runs with the -txindex flag set, so full indexing service is provided and data surfaced as-is.
The Bitcoin RPC is documented on the Bitcoin developer documentation, specifically here:
Descriptions of these JSON-RPC methods are reproduced below.
Bitcoin RPC
getblock
Returns block information.
getbestblockhash
Returns the hash of the best (tip) block in the most-work fully-validated chain.
getblockchaininfo
Returns an object containing various state info regarding blockchain processing.
getblockcount
Returns the height of the most-work fully-validated chain.
getblockhash
Returns hash of block in best-block-chain at height provided.
getblockheader
If verbose is false, returns a string that is serialized, hex-encoded data for blockheader ‘hash’.
If verbose is true, returns an Object with information about blockheader ‘hash’.
getblockstats
Returns block information.
getchaintips
Return information about all known tips in the block tree, including the main chain as well as orphaned branches.
getchaintxstats
Compute statistics about the total number and rate of transactions in the chain
getdifficulty
Returns the proof-of-work difficulty as a multiple of the minimum difficulty.
getmempoolancestors
If txid is in the mempool, returns all in-mempool ancestors.
getmempooldescendants
If txid is in the mempool, returns all in-mempool descendants.
getmempoolentry
Returns mempool data for given transaction
getmempoolinfo
Returns details on the active state of the TX memory pool.
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.
gettxout
Returns details about an unspent transaction output.
gettxoutproof
Returns a hex-encoded proof that “txid” was included in a block.
NOTE: By default this function only works sometimes. This is when there is an unspent output in the utxo for this transaction. To make it always work, you need to maintain a transaction index, using the -txindex command line option or specify the block in which the transaction is included manually (by blockhash).
gettxoutsetinfo
Returns statistics about the unspent transaction output set.
Note this call may take some time.
verifytxoutproof
Verifies that a proof points to a transaction in a block, returning the transaction it commits to and throwing an RPC error if the block is not in our best chain
Rawtransactions RPCs
analyzepsbt
btc_analyzepsbt analyzes and provides information about the current status of a PSBT and its inputs.
combinepsbt
btc_combinepsbt combines multiple partially signed PSBTs into a single PSBT. It takes partially signed transactions from various sources and consolidates them. This is important in multi-signature or complex transaction processes where each party contributes part of the transaction's data or signatures.
combinerawtransaction
btc_combinerawtransaction combines multiple partially signed raw transactions, in hexidecimal format, into one transaction. The combined transaction may be another partially signed transaction or a fully signed transaction. Each input transaction must have the same output structure to be successfully combined.
Useful for multi-signature transactions where each party signs the transaction separately. btc_combinerawtransaction collects these partial signatures and combines them into one transaction.
converttopsbt
btc_converttopsbt converts a standard Bitcoin raw transaction into a PSBT. This functionality is particularly useful when starting with a non-PSBT transaction format and needing to transition to a PSBT for multi-signature or advanced signing workflows. The conversion process ensures that the resulting PSBT remains unsigned, making it suitable for passing around to various parties for signatures.
createpsbt
btc_createpsbt creates a PSBT. It can be used for creating transactions that require multiple signatures or specific signing arrangements.
createrawtransaction
btc_createrawtransaction creates a new, raw, and unsigned Bitcoin transaction.
decodepsbt
btc_decodepsbt decodes a base64-encoded PSBT into a structured, readable format. The decoded output provides comprehensive information about the PSBT, including its inputs, outputs, any signatures it contains, and additional metadata.
decoderawtransaction
btc_decoderawtransaction decodes a serialized, hex-encoded transaction into a human-readable format.
decodescript
btc_decodescript is used to decode a hex-encoded script and provide human-readable details about it. The decoded information includes details such as the type of script (e.g., P2PKH, P2SH), required signatures, and any embedded addresses.
finalizepsbt
btc_finalizepsbt is used to finalize a Partially Signed Bitcoin Transaction (PSBT). This process involves completing the signing of the transaction and converting it into a fully signed transaction that is ready to be broadcast to the Bitcoin network.
Here's a breakdown of its functionality:
Completing Signatures: The primary function of
btc_finalizepsbtis to complete the signing of all inputs in the PSBT. It checks if all necessary signatures are present and valid for each input.Constructing the Final Transaction: Once all inputs are fully signed,
btc_finalizepsbtconstructs a final, standard Bitcoin transaction from the PSBT. This transaction is in a standard serialized transaction format, which is recognized and can be processed by the Bitcoin network.Ensuring Transaction Validity: The API call also checks that the transaction is valid. This includes ensuring that all inputs are correctly signed and that the transaction conforms to Bitcoin's transaction rules.
Extracting the Transaction: If the PSBT is fully signed,
btc_finalizepsbtextracts and returns the fully signed transaction in a hexadecimal string format. This string can then be directly submitted to the Bitcoin network for confirmation and inclusion in a block.Use in Multi-Party Transactions:
btc_finalizepsbtis particularly useful in multi-party transaction scenarios where a PSBT has been passed around multiple parties for signing. It provides a simple and secure way to finalize the transaction once all parties have provided their signatures.
getrawtransaction
btc_getrawtransaction retrieves detailed information about a specific transaction in the Bitcoin network. It's particularly useful for examining the details of transactions that are either in the mempool or already included in a block.
By default this function only works for mempool transactions. When called with a blockhash argument, btc_getrawtransaction will return the transaction if the specified block is available and the transaction is found in that block.
joinpsbts
btc_joinpsbts is used for joining multiple Partially Signed Bitcoin Transactions (PSBTs) into a single PSBT. PSBT is a standard format for Bitcoin transactions that are not fully signed, allowing for transactions to be passed around multiple parties for signing without revealing the private keys.
Functionality of btc_joinpsbts includes:
Combining Transactions: It takes multiple PSBTs as input and combines them into one. This is particularly useful in scenarios where different parties have created separate PSBTs for different inputs or outputs, and these need to be consolidated into a single transaction.
Facilitating Multi-Party Transactions: In situations where a transaction requires inputs or consents from multiple parties, each party can create their own PSBT.
btc_joinpsbtsthen merges these into a single PSBT that encompasses all the inputs, outputs, and signatures provided by the individual parties.Streamlining the Signing Process: Once the PSBTs are joined, the resulting single PSBT can be passed to each relevant party for signing. This streamlines the process, as each party can sign the same transaction instead of having to deal with multiple transactions.
Use in Complex Transaction Scenarios: This call is particularly useful in complex transaction scenarios like multi-signature transactions, CoinJoin transactions, or batch processing of transactions.
sendrawtransaction
Submit 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.
testmempoolaccept
btc_testmempoolaccept is used to test how a transaction would be received by the mempool without actually broadcasting it to the network. Here's an overview of its functionality:
Transaction Validation: It validates a raw transaction to check whether it would be accepted into the mempool. This validation includes various checks like transaction syntax, structure, and whether it meets the network's consensus rules.
Fee and Size Checks: The call assesses whether the transaction fees are adequate and if the transaction size is within acceptable limits.
Double-Spend Checks: It verifies that the transaction doesn't attempt to double-spend any UTXOs (Unspent Transaction Outputs).
Chain State Consideration: The API call considers the current state of the blockchain and the mempool to evaluate if the transaction would be accepted at that particular moment.
No Actual Broadcast: Importantly,
btc_testmempoolacceptdoes not broadcast the transaction to the network. It's a purely local test to see if the transaction would be accepted by the mempool under current conditions.Response Data: It returns information on whether the transaction would be accepted and, if not, provides details about why it would be rejected.
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 normalin getgly not rebroadcast non-wallet transactions already in their mempool.
utxoupdatepsbt
btc_utxoupdatepsbt updates a PSBT with information about the UTXOs it spends. This is particularly useful in scenarios where a PSBT lacks certain details about the UTXOs, which are necessary for signing and finalizing the transaction.
Util RPCs
createmultisig
btc_createmultisig creates a multi-signature address. Multi-signature addresses require more than one private key to authorize a transaction, enhancing the security of Bitcoin transactions
deriveaddresses
btc_deriveaddresses derives one or more addresses from an output descriptor. Output descriptors provide a human-readable way to describe Bitcoin addresses, including information about how to spend coins sent to these addresses.
estimatesmartfee
btc_estimatesmartfee estimates the transaction fee per kilobyte that should be included with a transaction in order to have it confirmed within a certain number of blocks. This estimation is based on the current state of the mempool and recent blocks.
getdescriptorinfo
btc_getdescriptorinfo provides information about a descriptor. A descriptor is a more expressive way to describe Bitcoin script types for wallets, including information on how to spend outputs sent to these addresses. The call calculates and returns a checksum for the descriptor, which is used to verify its integrity.
getindexinfo
btc_getindexinfo obtains information about the state of the blockchain indexes. These indexes are additional structures maintained by the node, which provide faster access to certain types of data, like transaction data or block information.
validateaddress
btc_validateaddress validates and provides detailed information about a Bitcoin address. If the address is valid, it provides detailed information about it, including the address type, whether it belongs to the wallet, and its associated public key (if available). For script addresses, it provides information about the script.
verifymessage
btc_verifymessage verifies a signed message. This function is used in scenarios where you need to prove ownership of a Bitcoin address or validate the authenticity of a message signed with a Bitcoin private key.
Last updated