The RPC Context
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.
-
The Rule: In the RPC context, all Hashes (Block Hashes, TXIDs, Merkle Roots) are returned in Big Endian (Human Order).
-
The Exception: In the raw binary data transmitted over the wire, these same hashes are Little Endian.
2. Why the RPC reverses data
The developers of Bitcoin Core wanted the command-line output to be usable by humans.
-
If you type
bitcoin-cli getblock 000000000019d6..., it's easy to see the zeros. -
If the RPC returned raw data, you would have to type
...d619000000000000, which is much harder to verify visually.
3. The txid vs. hash distinction
In a SegWit transaction, a transaction has both a txid and a hash (wtxid).
-
Both are 32 bytes.
-
Both are stored in Little Endian on disk.
-
Both are REVERSED by the RPC for display.
4. Numbers remain Natural
Interestingly, while hashes are reversed, large numbers are often kept in their logical order in JSON responses.
-
Value (Satoshis): Usually returned as a Decimal number (e.g.,
1.50000000), so endianness is irrelevant. -
Locktime: Returned as a standard integer.
5. Converting RPC to Raw
If you are building a raw transaction manually and you have a TXID from an RPC call, you must:
-
Take the RPC string (e.g.,
ABCD...). -
Reverse the bytes (e.g.,
...CDAB). -
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.
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: