Skip to main content

Aztec Macros

Aztec.nr provides macros (attributes) that transform your code during compilation to handle the complexities of private execution, proof generation, and state management.

Quick reference

Contract

AttributePurpose
#[aztec]Marks a module as an Aztec contract

Functions

AttributePurpose
#[external("private")]Client-side private execution with proofs
#[external("public")]Sequencer-side public execution
#[external("utility")]Unconstrained queries, not included in transactions
#[internal("private")]Private helper, only callable within the same contract
#[internal("public")]Public helper, only callable within the same contract
#[view]Prevents state modification
#[initializer]Contract constructor
#[noinitcheck]Callable before contract initialization
#[allow_phase_change]Allows for phase change to happen during the function's execution
#[only_self]Only callable by the same contract
#[authorize_once]Requires authwit authorization with replay protection

Functions can have multiple attributes (e.g., #[external("public")] with #[view] and #[only_self]).

Structs

AttributePurpose
#[note]Defines a private note type
#[custom_note]Note with custom hash/nullifier logic
#[storage]Defines contract storage layout
#[storage_no_init]Storage with manual slot allocation

For detailed explanations and examples, see the Attributes and Macros reference.

Further reading