Skip to main content

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:

PropertyDetail
Gas meteringEvery WASM instruction costs gas. Execution halts if the gas limit is reached.
State storageContracts read/write key-value state via ul_storage_get / ul_storage_set host calls.
Transaction contextContracts can read the caller's wallet address, block height, and transaction ID.
DeterminismNo floating point, no external I/O, no non-deterministic syscalls.
SandboxingMemory is isolated per invocation. Contracts cannot access each other's state directly.

Contract Lifecycle​

PhaseTransactionWho
DeployDEPLOY_CONTRACTOwner wallet uploads WASM bytecode
InvokeINVOKE_SMART_CONTRACTAny authorized wallet calls a function
AlterALTER_CONTRACTOwner enables/disables or updates metadata
QueryRead-only state fetch via HTTPAny 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 functionPurpose
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:

StandardEquivalentDescription
Fungible tokenERC-20Fixed-supply or mintable tokens with transfer/approve/allowance
Non-fungible tokenERC-721Unique token IDs with owner tracking
Multi-tokenERC-1155Batch operations over multiple token types

Detailed References​