TeachMeBitcoin

How to Read a Raw Script in Hex

From TeachMeBitcoin, the free encyclopedia Reading time: 2 min

1. How to Read a Raw Script in Hex

Introduction

Every Bitcoin transaction output carries a locking script (scriptPubKey), and every transaction input carries an unlocking script (scriptSig). These scripts are serialized as raw bytes and typically presented in hexadecimal form when you inspect raw transactions. Understanding how to read these hex sequences is the foundational skill for all further script debugging and analysis work.

When you request a raw transaction from the Bitcoin network or Bitcoin Core, the scripts appear as continuous hex strings. Without knowing the encoding rules, these strings look like random noise. Once you understand the structure, however, you can manually parse any script by hand.

The Encoding Rules

Bitcoin scripts are sequences of opcodes and data push elements. The encoding works as follows:

Full Opcode Reference Table (Selected)

| Hex | Decimal | Opcode Name | Description | |

Pro Tip

When debugging scripts, always start with a high-level disassembly before diving into the stack trace. Tools like bitcoin-cli decodescript are your first line of defense in identifying standard script patterns.

☕ 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!