Attribute Macro pbc_contract_codegen::init

source ·
#[init]
Expand description

Initializer contract annotation

REQUIRED HOOK: This is a required hook. A contract cannot be created without an initializer.

Init declares how the contract can be initialized. Init is an action that is forced to run to initialize the contract. Must occur exactly once in any given contract.

If the annotated function panics the contract will not be created.

Annotated function must have a signature of following format:

#[init]
pub fn initialize(
    context: ContractContext,
    // ... Invocation RPC arguments
) -> (ContractState, Vec<EventGroup>)

with following constraints:

Note that there are no previous state when initializing, in contrast to the action macro. If the initializer fails the contract will not be created.