#[contract]Expand description
Transforms a struct that represents a storage layout into a contract with helper methods to easily interact with the EVM storage. Its packing and encoding schemes aim to be an exact representation of the storage model used by Solidity.
§Input: Storage Layout
ⓘ
#[contract]
pub struct TIP20Token {
pub name: String,
pub symbol: String,
total_supply: U256,
#[slot(10)]
pub balances: Mapping<Address, U256>,
#[slot(11)]
pub allowances: Mapping<Address, Mapping<Address, U256>>,
}§Output: Contract with accessible storage via getter and setter methods.
The macro generates:
- Transformed struct with generic parameters and runtime fields
- Constructor:
_new(address, storage) - Type-safe (private) getter and setter methods
§Requirements
- No duplicate slot assignments
- Unique field names, excluding the reserved ones:
address,storage,msg_sender. - All field types must implement
Storable, and mapping keys must implementStorageKey.