Smart Contracts
ULedger smart contracts are WebAssembly (WASM) programs deployed on-chain and executed by the ULVM (ULedger Virtual Machine). They run in a deterministic, sandboxed environment and cannot access external state or perform I/O beyond what the host interface provides.
ULVM: The Runtime
The ULVM is a pure-Go WASM runtime built on wazero. Every contract invocation runs in an isolated WASM instance with:
| Property | Detail |
|---|---|
| Gas metering | Every WASM instruction costs gas. Execution halts if the gas limit is reached. |
| State storage | Contracts read/write key-value state via ul_storage_get / ul_storage_set host calls. |
| Transaction context | Contracts can read the caller's wallet address, block height, and transaction ID. |
| Determinism | No floating point, no external I/O, no non-deterministic syscalls. |
| Sandboxing | Memory is isolated per invocation. Contracts cannot access each other's state directly. |
Contract Lifecycle
| Phase | Transaction | Who |
|---|---|---|
| Deploy | DEPLOY_CONTRACT | Owner wallet uploads WASM bytecode |
| Invoke | INVOKE_SMART_CONTRACT | Any authorized wallet calls a function |
| Alter | ALTER_CONTRACT | Owner enables/disables or updates metadata |
| Query | Read-only state fetch via HTTP | Any client, no transaction required |
A deployed contract is identified by its contract address (the transaction ID of the DEPLOY_CONTRACT transaction).
Host Interface (ULVM ABI)
Contracts interact with ULedger state through a set of host functions imported from the ul module:
| Host function | Purpose |
|---|---|
ul_storage_get(key) | Read a contract state value |
ul_storage_set(key, value) | Write a contract state value |
ul_caller() | Get the invoking wallet address |
ul_block_height() | Get the current block height |
ul_emit(event, data) | Emit an event visible to subscribers |
Contracts export a call(function_name_ptr, args_ptr) entry point. The ULVM dispatches to the correct function based on the name.
Token Standards
The ULVM supports three built-in token standards implemented as WASM contracts:
| Standard | Equivalent | Description |
|---|---|---|
| Fungible token | ERC-20 | Fixed-supply or mintable tokens with transfer/approve/allowance |
| Non-fungible token | ERC-721 | Unique token IDs with owner tracking |
| Multi-token | ERC-1155 | Batch operations over multiple token types |
Detailed References
- Smart Contracts (agent-wallets section) - full ULVM ABI, gas table, council-voting contract walkthrough
- Smart Contracts and Tokens (Glossary) - token standard implementations
- Writing Smart Contracts guide
- REST API: Smart Contracts