ave-contract-sdk
Rust SDK for writing Ave Ledger smart contracts that are compiled to WebAssembly and executed by the Ave runtime.
The SDK keeps the contract-facing API small: contract authors define their state, event types, initialization checks, and update logic while the SDK handles host memory reads, serialization, deserialization, execution context creation, and result serialization.
Installation
Add the SDK to your contract crate:
[]
= "0.7.1"
= { = "1", = ["derive"] }
Contracts that are compiled for the Ave runtime should expose a cdylib artifact:
[]
= ["cdylib"]
This crate currently requires Rust 1.91.0 or newer and uses the Rust 2024 edition.
Contract Interface
An Ave contract exposes two C ABI functions to the runtime:
init_check_function(state_ptr: i32) -> u32main_function(state_ptr: i32, init_state_ptr: i32, event_ptr: i32, is_owner: i32) -> u32
Those exported functions delegate to the SDK:
check_init_datavalidates the initial state before contract creation.execute_contractapplies an event to the current state and returns the final state plus the execution status.
The runtime passes state and event data through WASM host memory. The SDK decodes that data using Borsh-wrapped JSON values, converts it into the contract's Rust types with serde, runs the callback provided by the contract, and stores the serialized result back in WASM memory for the host.
Minimal Contract
use ave_contract_sdk as sdk;
use ;
pub unsafe
pub unsafe
Build the contract for WebAssembly:
Public API
check_init_data
Validates the proposed initial state. The callback receives the deserialized state and a mutable ContractInitCheck. Set success = true to accept the state, or set success = false and provide error to reject it.
execute_contract
Executes one event against the current state. If the current state cannot be converted into the contract state type, the SDK attempts to recover from init_state_ptr. The callback receives a Context<Event> and a mutable ContractResult<State>.
Set result.success = true when the event should be accepted. Leave it as false, or set it explicitly to false, and fill result.error when the event should be rejected.
Core Types
Context<Event>
Execution context passed to contract logic:
event: the deserialized event being applied.is_owner:truewhen the runtime reports that the event sender is the owner.
ContractResult<State>
Mutable result passed to event logic:
state: final state candidate.success: whether the runtime should apply the state change.error: rejection reason whensuccess == false.
New values created with ContractResult::new(state) start with success = false, so contract logic must explicitly accept successful changes.
ContractInitCheck
Mutable result passed to initialization checks:
success: whether the initial state is valid.error: rejection reason whensuccess == false.
Examples
The repository includes two non-published example crates:
example: contract with several event variants and a rejected update path.example2: minimal string update contract.
Run their tests from the repository root:
Development
Run the SDK test suite:
Check what would be included in the crates.io package:
The crate is configured as both rlib and cdylib so it can be used by Rust tests and by contracts compiled for WASM.
Publishing Notes
Before publishing a new release, verify:
Cargo.tomlhas the intendedversion,repository,homepage,license,keywords, andreadmevalues.- The README installation snippet matches the crate version being published.
cargo testpasses.cargo package --listcontains only files that should be distributed.- The dependent
ave-commonversion is available on crates.io.
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.