ave-contract-sdk
Rust SDK for writing Ave Ledger contracts compiled to WASM.
What it does
ave-contract-sdk handles the repetitive part of a contract:
- Reads state and event data from WASM host memory.
- Converts those values into Rust types with
serde. - Executes the contract logic through a callback.
- Returns the serialized result so the runtime can apply or reject the state change.
The contract only needs to define:
- The state type.
- The event type.
- The initial state validation.
- The logic that updates the state.
What it receives and what it returns
The public API is intentionally small.
check_init_data
Validates the initial state before the contract is created.
Receives:
state_ptr: i32: pointer to the initial state in host memory.callback: function with signaturefn(&State, &mut ContractInitCheck).
Does:
- Reads and deserializes the initial state.
- Runs the validation logic defined by the contract.
Returns:
u32: pointer to the serialized result withsuccessanderror.
execute_contract
Executes an event against the current state.
Receives:
state_ptr: i32: pointer to the current state.init_state_ptr: i32: pointer to the initial state; used as a fallback if the current state does not exist yet or cannot be recovered.event_ptr: i32: pointer to the incoming event.is_owner: i32:1if the event sender is the owner,0otherwise.callback: function with signaturefn(&Context<Event>, &mut ContractResult<State>).
Does:
- Deserializes state and event.
- Builds
Context<Event>. - Runs the contract logic.
- Serializes the final state and execution result.
Returns:
u32: pointer to the serialized result withfinal_state,success, anderror.
Types you will use
Context<Event>
Describes the execution context:
event: event that triggers the logic.is_owner: whether the operation is performed by the owner.
ContractResult<State>
Execution result:
state: final state.success: whether the change should be applied.error: rejection reason whensuccess == false.
ContractInitCheck
Initial validation result:
success: whether the initial state is valid.error: rejection reason.
Minimal example
use ave_contract_sdk as sdk;
use ;
pub unsafe
pub unsafe
You can find complete examples in:
Contract flow
- The runtime calls
init_check_functionto validate the initial state. - The runtime calls
main_functionto apply an event. - The contract updates
result.state. - The contract sets
result.success = trueor provides an explicit error.
Repository structure
src/lib.rs: public SDK API.src/externf.rs: external functions used to interact with host memory.src/error.rs: internal SDK errors.tests/integration_tests.rs: integration tests.example/src/lib.rs: example with multiple events.example2/src/lib.rs: minimal example.
Development
Run the test suite with:
The SDK uses serde to map state and events, and borsh for binary exchange with the WASM runtime.
License
This project is a fork of kore-contract-sdk, originally developed by Kore Ledger, SL, modified in 2025 by Averiun Ledger, SL, and distributed under the same AGPL-3.0-only license.