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:
ContractState
must be the type annotated withstate
, and must have anpbc_traits::ReadWriteState
implementation.- Additional arguments are must have
pbc_traits::ReadRPC
andpbc_traits::WriteRPC
implementations. These are treated as invocation arguments, and are included in the ABI.
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.