Indexing and State Management

Building and running a custom indexer is fundamental for the operation of the Universal BRC-20 Extension. Unlike base Bitcoin which achieves consensus through mining and full nodes, the BRC-20 token state (supplies, balances, etc.) is an interpretation layer maintained off-chain by indexers who follow the protocol's rules based on on-chain data.

  1. Blockchain Scanning: Indexers continuously scan the Bitcoin blockchain for new blocks and transactions.
  2. Transaction Filtering: Identify relevant transactions by filtering for those containing an OP_RETURN output where the data payload starts with the specific BRC-20 protocol identifier (p":"brc-20). The hex representation of this minified JSON must be present immediately after the OP_RETURN opcode and its length prefix.
  3. Operation Parsing: Decode the data payload in the OP_RETURN output as compact JSON and parse the BRC-20 operation details (op, tick, amt, etc.).
  4. Consensus Rule Validation: For each parsed operation, apply the strict BRC-20 consensus rules (see section below) to determine its validity. Invalid operations MUST be ignored.
    • Check OP_RETURN formatting and size (especially the 80-byte limit).
    • Validate JSON schema and required fields.
    • Crucially, enforce Namespace Uniqueness for deploy operations, checking against both 4-character (Ordinals) and >=4-character (OP_RETURN) existing deploys for the exact ticker string.
    • Validate mint amounts against deploy limits (l) and total supply (m).
    • Validate transfer amounts against the sender's available balance (tracked by the indexer) and deploy limits (l).
    • Validate input UTXOs correspond to known token balances for the sender.
    • Validate standard output structure (e.g., dust limit).
  5. State Update: Based on the validation outcome:
    • For a valid deploy, register the new token and its parameters (tick, m, l).
    • For a valid mint, update the total minted supply for the token and allocate the minted amount to the addresses controlling the eligible standard outputs according to the Proportional Distribution rule, associating the balance with the new UTXOs.
    • For a valid transfer, decrease the sender's balance (by de-associating balance from spent input UTXOs) and allocate the transferred amount to the addresses controlling the new eligible standard outputs according to the Proportional Distribution rule, associating the balance with these new UTXOs. Handle rounding remainders based on defined policy.
  6. Balance Tracking: Maintain a database associating specific UTXOs with specific token amounts for each token type and address. An address's total balance is the sum of token amounts on all UTXOs it controls that the indexer recognizes as token-bearing.