TeachMeBitcoin

The RPC Context

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

The RPC Context

The Bitcoin Remote Procedure Call (RPC) interface is the primary way that developers interact with a Bitcoin node. However, the RPC interface performs several "Silent Reversals" of byte data that can be extremely confusing if you are expecting the raw format.

1. The "Reversed" Hashes

When you call getblockhash or getrawtransaction, the node returns hex strings.

2. Why the RPC reverses data

The developers of Bitcoin Core wanted the command-line output to be usable by humans.

3. The txid vs. hash distinction

In a SegWit transaction, a transaction has both a txid and a hash (wtxid).

4. Numbers remain Natural

Interestingly, while hashes are reversed, large numbers are often kept in their logical order in JSON responses.

5. Converting RPC to Raw

If you are building a raw transaction manually and you have a TXID from an RPC call, you must:

  1. Take the RPC string (e.g., ABCD...).

  2. Reverse the bytes (e.g., ...CDAB).

  3. Insert that result into your transaction blob.

If you skip this step, your transaction will try to spend from a non-existent UTXO because the node will be looking for the "Reversed" ID.

Interface Hash Format Byte Order
bitcoin-cli Display String Big Endian
JSON-RPC JSON String Big Endian
Raw P2P Binary Stream Little Endian

In the next section, we will discuss The Cryptographic Context.

☕ Help support TeachMeBitcoin

TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!