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

Primitive Types

Cambrian provides built-in primitives for booleans, integers, text, bytes, and addresses.

Boolean

TypeValues
booltrue, false

Unsigned integers

TypeRangeTypical use
u80…255Flags, small counters
u160…65 535Small IDs
u320…2³²−1Medium IDs
u640…2⁶⁴−1General counters
u1280…2¹²⁸−1Large counters
usizeuint256 on EVM, Nat on LeanCollection indices

On EVM, narrow integers keep their declared Solidity widths (uint8, …) in structs and storage. Widened uint256 results from arithmetic / timestamps / msg::value are narrowed with casts only when the binding requires it.

Signed integers

i8, i16, i32, i64, i128 — available when negative values are needed.

Large integers

TypeEVM typeUse
U256uint256Token amounts, balances, wide math
m_balance: U256 {
    in deposit(amount) => m_balance + amount
}

String and bytes

TypeDescription
StringUTF-8 text
bytesRaw byte sequence (b"…" literals)
bytes32Fixed 32-byte value (hashes)

String↔number conversion is never implicit — use std::str::parse_* / std::str::format (Standard Library).

Address

TypeDescription
addressParty or entity address

Prefer Address<Entity> when sending named messages — see Generic Types.

pubkey

TypeNotes
pubkeyA 256-bit key value (bytes32 on EVM). It is not part of the EVM message/system context — prefer address and msg::sender for access control.

Summary

TypeCommon use
boolFlags, conditions
u8…u128, i8…i128Counters, IDs, offsets
U256Balances and amounts
String / bytesText and payloads
addressCallers and destinations