Skip to main content

What a contract looks like

Example Contract

In keeping with the origins of blockchain, here's an example of a simple private token contract. Everyone's balances are private.

contract EasyPrivateToken {
use dep::aztec::prelude::{AztecAddress, NoteHeader, Map};
use dep::value_note::{balance_utils, value_note::ValueNote};
use dep::easy_private_state::EasyPrivateUint;

struct Storage {
balances: Map<AztecAddress, EasyPrivateUint>,

* initialize the contract's initial state variables.
fn constructor(initial_supply: u64, owner: AztecAddress) {
let balances = storage.balances;, owner);

// Mints `amount` of tokens to `owner`.
fn mint(amount: u64, owner: AztecAddress) {
let balances = storage.balances;, owner);

// Transfers `amount` of tokens from `sender` to a `recipient`.
fn transfer(amount: u64, sender: AztecAddress, recipient: AztecAddress) {
let balances = storage.balances;, sender);, recipient);

// Helper function to get the balance of a user ("unconstrained" is a Noir alternative of Solidity's "view" function).
unconstrained fn get_balance(owner: AztecAddress) -> pub Field {
let balances = storage.balances;

// Return the sum of all notes in the set.
Source code: noir-projects/noir-contracts/contracts/easy_private_token_contract/src/

The prelude consists of more commonly imported aztec types that are needed for development. Here is what the prelude includes:

use dep::protocol_types::{address::{AztecAddress, EthAddress}, abis::function_selector::FunctionSelector};
use crate::{
map::Map, private_immutable::PrivateImmutable, private_mutable::PrivateMutable,
public_immutable::PublicImmutable, public_mutable::PublicMutable, private_set::PrivateSet,
shared_immutable::SharedImmutable, storage::Storable
log::{emit_unencrypted_log, emit_encrypted_log}, context::PrivateContext,
note_header::NoteHeader, note_interface::NoteInterface, note_getter_options::NoteGetterOptions,
utils::compute_note_hash_and_nullifier as utils_compute_note_hash_and_nullifier
Source code: noir-projects/aztec-nr/aztec/src/

Please note that any example contract set out herein is provided solely for informational purposes only and does not constitute any inducement to use or deploy. Any implementation of any such contract with an interface or any other infrastructure should be used in accordance with applicable laws and regulations.