Example: Genesis block coinbase transaction
10. Reading Scripts from a Block Explorer
What Block Explorers Show
Block explorers parse raw transaction data and display scripts in human-readable form. Understanding the mapping between what you see on a block explorer and the underlying bytes is essential for debugging.
Popular Block Explorers and Their Script Views
Mempool.space — Shows scriptpubkey_type, scriptpubkey_asm, scriptpubkey_address for outputs, and scriptsig_asm, witness for inputs.
Blockstream.info — Similar structure; API returns raw JSON.
Blockchair — Provides rich query capabilities; useful for aggregate script analysis.
Reading from mempool.space API
import requests
def get_tx_scripts(txid: str) -> dict:
url = f"https://mempool.space/api/tx/{txid}"
resp = requests.get(url)
resp.raise_for_status()
tx = resp.json()
result = {"inputs": [], "outputs": []}
for inp in tx["vin"]:
result["inputs"].append({
"txid": inp["txid"],
"vout": inp["vout"],
"scriptsig_hex": inp.get("scriptsig", ""),
"scriptsig_asm": inp.get("scriptsig_asm", ""),
"witness": inp.get("witness", []),
})
for out in tx["vout"]:
sp = out["scriptpubkey"]
result["outputs"].append({
"value": out["value"],
"scriptpubkey_hex": sp,
"scriptpubkey_type": out.get("scriptpubkey_type"),
"address": out.get("scriptpubkey_address"),
})
return result
# Example: Genesis block coinbase transaction
tx = get_tx_scripts("4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b")
for out in tx["outputs"]:
print(out)
Understanding ASM Representation
Block explorers display scripts in ASM format: opcodes by name, data as hex. For example:
OP_DUP OP_HASH160 89abcdef...abba OP_EQUALVERIFY OP_CHECKSIG
The data segments (like 89abcdef...abba) are the raw hex of the pushed bytes, without the length prefix byte. The length byte is implicit in ASM notation.
Identifying Script Types by Visual Pattern
| ASM Pattern | Type | |
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.
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: