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

Message Context (msg::)

The msg:: namespace describes the inbound call that triggered the current route. Values are available in route actions, where / from clauses, macros, and member transforms — not in pure fn or pure routes.

Primary fields (EVM)

FieldTypeDescriptionSolidity loweringLean
msg::senderaddressCaller of this callmsg.senderyes
msg::valueU256Native currency attached to the callmsg.valueyes

These are the fields you should rely on for access control and payable logic. An unknown msg:: field is rejected.

Optional time alias

FieldNotes
msg::timestampLowers to block.timestamp on EVM and is modelled on Lean. Prefer sys::now / sys::timestamp when you mean block time, so message context and system context stay distinct.

msg::sender

macro is_owner() -> bool = {
    msg::sender == m_owner
}

routes {
    withdraw(amount: U256)
        where @is_owner() : throw Unauthorized()
    => [
        ~> msg::sender with { value: amount }
    ]
}

In transforms:

m_last_caller: address {
    in deposit() => msg::sender
}

m_balances: HashMap<address, U256> {
    in deposit() => {
        let current = m_balances[msg::sender];
        m_balances.insert(msg::sender, current + msg::value)
    }
}

msg::value

routes {
    deposit()
        where msg::value > 0 : throw ZeroDeposit()
    => []
}

m_balance: U256 {
    in deposit() => m_balance + msg::value
}

Routes (or transforms) that read msg::value are treated as payable on EVM so callers can attach native currency.

Usage contexts

ContextExample
Where clauseswhere msg::sender == m_owner : throw Unauthorized()
Route actions~> msg::sender with { value: amount }
Member transformsin deposit() => msg::value
Macrosmacro is_owner() -> bool = { msg::sender == m_owner }

For block / chain / balance environment reads, see System Context.