Example Contracts¶
The chain repository includes four example contracts under packages/contracts/. Each targets wasm32-wasip2 and uses wit_bindgen to generate bindings from the WIT ABI.
counter¶
A minimal contract that maintains a single integer value.
- init: set the counter to an initial value (default 0)
- exec:
Increment,Decrement, orResetthe counter (with overflow/underflow checks) - query:
GetCountreturns the current value - Events: emits
counter_initandcounter_changed
Demonstrates basic KV storage (kv-get, kv-set), event emission, and JSON message handling with serde.
Source: packages/contracts/counter/src/lib.rs
token¶
A simple fungible token contract.
- init: set total supply and mint all tokens to the creator
- exec: transfer tokens between addresses
- query: check balance, total supply, or token metadata
Demonstrates multi-key storage patterns (one key per holder address) and sender-based authorization via get-sender.
Source: packages/contracts/token/src/lib.rs
kv¶
A generic key-value store contract.
- init: no-op initialization
- exec: set or delete arbitrary key-value pairs
- query: get a value by key, or check existence
Demonstrates direct pass-through to the host KV functions. Useful as a building block or for testing.
Source: packages/contracts/kv/src/lib.rs
proxy¶
Demonstrates cross-contract calls using the dispatch/reply pattern.
- init: stores a target contract address
- exec: forwards messages to the target via
dispatchwithReplyOn::Always - query: returns the last reply data received
- reply: stores the sub-message result in KV
Demonstrates dispatch, reply, and ReplyOn usage. Pair it with any other contract to test cross-contract communication.
Source: packages/contracts/proxy/src/lib.rs