WIT ABI Reference
The contract host ABI is defined in config/wit/contract.wit as chain:contract@1.0.0. All host functions are imported through the host interface.
Storage
| Function |
Signature |
Description |
kv-get |
func(key: string) -> option<list<u8>> |
Read a value from the contract's KV namespace. Returns None if the key does not exist. |
kv-set |
func(key: string, value: list<u8>) |
Write a value. Traps if called during a query. |
kv-delete |
func(key: string) |
Delete a key. Traps if called during a query. |
kv-has |
func(key: string) -> bool |
Check whether a key exists without reading the value. |
Events
| Function |
Signature |
Description |
emit-event |
func(kind: string, data: list<u8>) |
Emit an event with a type tag and arbitrary data. Traps during queries. |
Context
| Function |
Signature |
Description |
get-sender |
func() -> list<u8> |
Address of the immediate caller. For top-level transactions this is the signer. For sub-messages this is the dispatching contract. |
get-origin |
func() -> list<u8> |
Address of the original transaction signer. Unchanged across sub-message depth. |
get-self-address |
func() -> list<u8> |
Address of the currently executing contract. |
get-block-height |
func() -> u64 |
Current block height. |
Logging
| Function |
Signature |
Description |
log |
func(msg: string) |
Write a debug log line. Available in dev mode; may be no-op in production. |
Cross-contract communication
| Function |
Signature |
Description |
dispatch |
func(target: list<u8>, msg: list<u8>, reply-on: reply-on, funds: u64) -> result<u64, string> |
Queue a sub-message for deferred execution. Returns a locally-unique message ID used for routing replies. See Cross-Contract Calls. |
query-contract |
func(target: list<u8>, msg: list<u8>) -> result<list<u8>, string> |
Synchronously query another contract (read-only, no state changes). |
ReplyOn enum
The reply-on parameter on dispatch controls when the reply export is invoked:
| Variant |
Behavior |
never |
Fire and forget. Sub-message failure reverts the entire transaction. |
success |
Reply only on success. Failure reverts the entire transaction. |
error |
Reply only on error. Success does not trigger a reply. |
always |
Reply on both success and error. |