Box Modelling
Advanced patterns and techniques for modeling complex state
Box Modelling Overview
Good Ergo applications model protocol state as a small set of boxes with explicit ownership, register layout, and transition rules. The goal is to make every valid state transition easy to construct off-chain and cheap to verify on-chain.
State boxes
Use a dedicated box to represent protocol state, then require the next output to preserve identifiers, update registers, and keep required tokens.
Register schema
Assign stable meanings to R4-R9, document their types, and validate those types in ErgoScript before trusting the data.
Read-only context
Use data inputs for oracle boxes, reference boxes, and other shared facts that a transaction needs to read without spending.
Off-chain builders
Keep complex search, selection, and balancing logic off-chain. ErgoScript should check the invariant, not reconstruct the whole protocol.