Technical Annexes
OP_RETURN Script Calculation
Constructing the OP_RETURN output script requires careful encoding of the BRC-20 JSON payload into hexadecimal bytes formatted correctly for a Bitcoin Script data push.
- Start with the OP_RETURN opcode hex:
6a
. - Generate the minified JSON string for the desired BRC-20 operation following the specification.
- Encode this JSON string into its raw byte representation, then convert those bytes to their hexadecimal string representation.
- Determine the length of the raw JSON bytes.
- Prepend the length bytes according to Bitcoin script data push rules (opcodes 0x01 to 0x4e are permitted after OP_RETURN, as per standard policy/interpretation, respecting the 80-byte limit):
- If length is 0 bytes (empty payload, though not used in current BRC-20 ops), use a push of 0 bytes (e.g.,
4c00
). - If length is 1 to 75 bytes, prepend a single byte indicating the length (e.g.,
0c
for 12 bytes). - If length is 76 to 80 bytes (current max policy limit), prepend
4c
(OP_PUSHDATA1) followed by a single byte indicating the length (e.g.,4c50
for 80 bytes). - (Larger lengths using OP_PUSHDATA2
4d
or OP_PUSHDATA44e
are technically possible in script but are restricted by the current 80-byte OP_RETURN policy limit).
- If length is 0 bytes (empty payload, though not used in current BRC-20 ops), use a push of 0 bytes (e.g.,
- Concatenate the OP_RETURN opcode (
6a
), the length prefix bytes, and the hex payload data. This forms the complete OP_RETURN script.
Example:
For the minified JSON p":"brc-20
, which is 12 bytes:
- Raw bytes:
p":"brc-20
- Hex:
7b2270223a226272632d3230227d
- Length: 12 bytes
- Length Prefix:
0c
(single byte push for length 12) - Full OP_RETURN Script Hex:
6a0c7b2270223a226272632d3230227d
Transaction Verification & Signing Workflow
A typical workflow for creating and broadcasting a BRC-20 transaction with this extension, ensuring it follows both Bitcoin and BRC-20 protocol rules:
- Prepare Transaction Inputs and Outputs:
- Select necessary input UTXOs (ensure sufficient BTC for fees and output values; choose token-bearing UTXOs if performing a
transfer
). - Define standard outputs: recipient addresses and desired satoshi amounts (MUST meet dust limit).
- Define a change output if necessary.
- Select necessary input UTXOs (ensure sufficient BTC for fees and output values; choose token-bearing UTXOs if performing a
- Create BRC-20 Payload: Construct the JSON string for the desired operation (
deploy
,mint
, ortransfer
) following the specification. Minify the JSON to save space. Ensure the ticker meets the length requirement (>= 4 chars) and the entire JSON payload will fit within the 80-byte limit. - Encode OP_RETURN Script: Convert the minified JSON payload to hex bytes and prepend the correct OP_RETURN opcode and length prefix as described above. This is the hex string for the OP_RETURN output's scriptPubKey.
- Build Raw Transaction: Assemble the transaction using Bitcoin RPC commands (
createrawtransaction
) or a library. Include the selected inputs, standard outputs, change output, and the OP_RETURN output with value 0 and the constructed OP_RETURN script. - Decode and Validate (Crucial Step): Use
bitcoin-cli decoderawtransaction
or a similar tool to examine the raw transaction bytes. Strictly verify:- Inputs and outputs are correct.
- The OP_RETURN output is present at vout 0.
- The OP_RETURN script starts with
6a
followed by a valid length prefix. - The data payload in the OP_RETURN exactly matches the hex encoding of the intended minified BRC-20 JSON.
- The OP_RETURN data payload does NOT exceed 80 bytes.
- No extraneous data exists after the BRC-20 payload in the OP_RETURN script.
- Standard outputs meet the dust limit.
- Sign Transaction: Use
bitcoin-cli signrawtransactionwithkey
orsignrawtransactionwithwallet
to sign the inputs. - Broadcast Transaction: Use
bitcoin-cli sendrawtransaction
to send the signed transaction to the Bitcoin network. - Monitor Confirmation and Indexer Status: Track the transaction's confirmation status on the blockchain. Monitor a compliant BRC-20 indexer to ensure the transaction was processed and interpreted correctly, and that token balances were updated as expected. Be aware that indexers might have slight delays or differences in interpreting complex scenarios or transactions near the 80-byte limit.
Universal BRC-20 Extension
An unofficial protocol built on Bitcoin's OP_RETURN, aiming to provide a simpler, more flexible, and multi-recipient-friendly method for BRC-20 operations, relying on indexers for state management and sharing the global BRC-20 ticker namespace. This version allows tickers of 4 or more characters, constrained by the 80-byte OP_RETURN limit. Users MUST understand the reliance on indexers for token state validation and the importance of proper UTXO management.