Skip to content
Pre-Release: Fe is under active development. This documentation covers the upcoming release. Follow progress on GitHub

Intrinsics Reference

Intrinsics are built-in functions that provide direct access to EVM operations and low-level functionality. This appendix documents available intrinsics in Fe.

These intrinsics provide information about the execution context:

IntrinsicReturnsDescription
caller()AddressAddress that called this contract
block_number()u256Current block number
block_timestamp()u256Current block timestamp (seconds since epoch)
block_coinbase()AddressCurrent block miner/validator address
block_difficulty()u256Current block difficulty
block_gaslimit()u256Current block gas limit
chain_id()u256Current chain ID
origin()AddressOriginal transaction sender
gas_price()u256Gas price of the transaction
gas_remaining()u256Remaining gas for execution
fn only_owner(owner: Address) uses (ctx: Ctx) {
assert(ctx.caller() == owner, "not owner")
}
fn get_timestamp() -> u256 uses (ctx: Ctx) {
ctx.block_timestamp()
}

These intrinsics relate to contract state and identity:

IntrinsicReturnsDescription
self_address()AddressThis contract’s address
balance(addr)u256ETH balance of address (in wei)
self_balance()u256This contract’s ETH balance
code_size(addr)u256Size of code at address
code_hash(addr)u256Keccak256 hash of code at address
fn get_contract_balance() -> u256 {
self_balance()
}
fn is_contract(addr: Address) -> bool {
code_size(addr) > 0
}

Hash functions and cryptographic operations:

IntrinsicReturnsDescription
keccak256(data)u256Keccak-256 hash
sha256(data)u256SHA-256 hash
ripemd160(data)u256RIPEMD-160 hash
ecrecover(hash, v, r, s)AddressRecover signer from signature
fn hash_value(value: u256) -> u256 {
keccak256(value)
}
fn verify_signature(
message_hash: u256,
v: u8,
r: u256,
s: u256,
expected_signer: Address
) -> bool {
let signer = ecrecover(message_hash, v, r, s)
signer == expected_signer
}

Control flow for error handling:

IntrinsicDescription
assert(condition, message)Revert if condition is false
revertUnconditionally revert execution
todo()Placeholder that always reverts
fn transfer(from: Address, to: Address, amount: u256) {
assert(from != Address::zero(), "transfer from zero address")
assert(to != Address::zero(), "transfer to zero address")
assert(balance >= amount, "insufficient balance")
if some_condition {
revert
}
}
fn not_implemented() {
todo()
}

For calling other contracts:

IntrinsicDescription
call(addr, value, data)Call another contract
staticcall(addr, data)Read-only call (no state changes)
delegatecall(addr, data)Call using this contract’s storage
fn send_eth(to: Address, amount: u256) -> bool {
let (success, _) = call(to, amount, [])
success
}

Low-level memory operations:

IntrinsicDescription
mload(offset)Load 32 bytes from memory
mstore(offset, value)Store 32 bytes to memory
msize()Current memory size

These are rarely needed in Fe as the compiler manages memory automatically.

Direct storage access:

IntrinsicDescription
sload(slot)Load from storage slot
sstore(slot, value)Store to storage slot

Fe’s storage system abstracts over these. Use storage structs and effects instead.

Event emission:

IntrinsicDescription
log.emit(event)Emit an event to the transaction log
struct TransferEvent {
#[indexed]
from: Address,
#[indexed]
to: Address,
value: u256,
}
fn emit_transfer(from: Address, to: Address, value: u256) uses mut log: Log {
log.emit(TransferEvent { from, to, value })
}
IntrinsicDescription
msg_value()ETH sent with the current call
fn deposit() uses (ctx: Ctx) {
let amount = ctx.msg_value()
// Process deposit...
}
IntrinsicReturnsDescription
block_hash(number)u256Hash of a recent block (last 256 blocks)
fn get_recent_block_hash(block_num: u256) -> u256 {
block_hash(block_num)
}
CategoryIntrinsics
Contextcaller, block_number, block_timestamp, chain_id, etc.
Contractself_address, balance, code_size, code_hash
Cryptokeccak256, sha256, ecrecover
Controlassert, revert, todo
Callscall, staticcall, delegatecall
Eventslog.emit
  1. Use effects instead of raw intrinsics - Fe’s effect system (uses Ctx, uses Log) provides safer access to intrinsics

  2. Avoid low-level storage/memory - Let Fe manage these automatically

  3. Check ecrecover results - Always verify the recovered address is not zero

  4. Be careful with block_hash - Only works for the last 256 blocks

  5. Handle call failures - External calls can fail; always check return values