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

Message Fields

Message fields define the parameters that callers pass when invoking a message variant.

Fields are defined inside curly braces, similar to struct fields:

#[selector = 0xa9059cbb]
Transfer { to: u256, amount: u256 } -> bool,

Each field has:

  • A name (to, amount)
  • A type (u256)

Multiple fields are separated by commas.

Message fields support all Fe types:

msg Example {
#[selector = 0x00000001]
WithPrimitives {
flag: bool,
count: u256,
signed_value: i128,
},
}
msg Example {
#[selector = 0x00000002]
WithTuple { coords: (u256, u256) } -> bool,
}

Variants can have no fields:

msg Query {
#[selector = 0x18160ddd]
TotalSupply -> u256,
#[selector = 0x06fdde03]
Name -> String,
}

Field order is significant for ABI encoding. The order in which fields are defined determines how calldata is decoded:

// These are different!
msg Example1 {
#[selector = 0xa9059cbb]
Transfer { to: u256, amount: u256 },
}
msg Example2 {
#[selector = 0xa9059cbb]
Transfer { amount: u256, to: u256 },
}

When implementing standard interfaces like ERC20, ensure field order matches the specification.

In recv blocks, destructure fields to access their values:

recv TokenMsg {
Transfer { to, amount } -> bool {
// 'to' and 'amount' are available here
true
}
}

You can also rename fields during destructuring:

recv TokenMsg {
Transfer { to: recipient, amount: value } -> bool {
// Use 'recipient' and 'value' instead
true
}
}

Use _ to ignore fields you don’t need:

recv TokenMsg {
Transfer { to, amount: _ } -> bool {
// Only use 'to', ignore amount
true
}
}

Use .. to ignore remaining fields:

recv TokenMsg {
TransferFrom { from, .. } -> bool {
// Only use 'from', ignore to and amount
true
}
}
PatternMeaning
{ field: Type }Named field with type
{ a, b, c }Multiple fields
(no braces)No parameters
{ field }Destructure keeping name
{ field: name }Destructure with rename
{ field: _ }Ignore specific field
{ field, .. }Ignore remaining fields