Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

System Context (sys::)

The sys:: namespace describes the execution environment for the current route (time, self address, balance, and related host fields). Values are available in route actions, where clauses, macros, and member transforms — not in pure fn or pure routes.

Fields commonly used on EVM

FieldDescriptionTypical EVM loweringLean
sys::now / sys::timestampBlock / host timestampblock.timestampyes
sys::block_numberBlock numberblock.numberyes
sys::chainidChain idblock.chainidyes
sys::addressThis entity’s addressaddress(this)yes
sys::balanceThis entity’s native balanceaddress(this).balanceyes
sys::coinbaseBlock coinbaseblock.coinbase—
sys::basefeeBlock base feeblock.basefee—
sys::blobbasefeeBlob base fee (EIP-4844)block.blobbasefee—
sys::prevrandaoBlock randomnessblock.prevrandao—
sys::gas_leftRemaining gasgasleft()—
sys::origintx.origin (use sparingly)tx.origin—
sys::gaspriceTransaction gas pricetx.gasprice—

Fields marked “—” are EVM-only: the Lean model has no counterpart, and they are rejected when compiling for Lean.

For property / invariant ctx blocks, the validated context names are the portable subset: msg::{sender,value} and sys::{now,timestamp,chainid,block_number,balance} (T20).

Time guards

routes {
    claim()
        where (sys::now >= m_unlock_time) : throw TooEarly()
    => [
        ~> msg::sender with { value: m_amount }
    ]
}
m_last_action: u64 {
    in deposit() => sys::now
    in withdraw(_) => sys::now
}

Own address and balance

routes {
    sweep(to: address) => [
        ~> to with { value: sys::balance }
    ]
}

Prefer sys::balance for “this entity’s balance.” Use evm::balance(addr) when you need another account’s balance on EVM (see EVM Intrinsics).

Not for pure code

pure fn and pure routes cannot read sys::* (or msg::*) — those namespaces are impure by definition.