An Aztec Noir contract demonstrating how to create and use custom note types in the Aztec protocol.
This project showcases how to define a custom note structure with multiple fields and use it in a private smart contract. The contract stores custom notes in a private state that can only be viewed by the note owner.
The CustomNote contains:
- a, b, c, d: Four arbitrary
Fieldvalues for custom data - randomness: A random
Fieldvalue to ensure note privacy - owner: The
AztecAddressof the note owner
A private function that creates and stores a new custom note.
- Parameters: Four field values (a, b, c, d)
- Behavior: Creates a note with the provided values and assigns ownership to the message sender
- Privacy: Emits the note using unconstrained onchain message delivery
An unconstrained utility function to view all custom notes for a given owner.
- Parameters: Owner's Aztec address
- Returns: Array of custom notes (up to
MAX_NOTES_PER_PAGE) - Usage: Can be called to query notes without consuming gas
Compile the contract using the Aztec CLI:
aztec compile-
Deploy the contract to an Aztec network
-
Insert a custom note:
CustomNote.insert(field1, field2, field3, field4)- View notes for an address:
CustomNote.view_custom_notes(owner_address)- Demonstrates custom note type implementation with the
#[note]macro - Shows how to use
PrivateSetstorage for managing multiple notes per user - Implements proper note privacy using randomness
- Provides getter methods for accessing individual note fields
- Aztec v5.0.0-rc.1
To set this version:
aztec-up 5.0.0-rc.1custom-note/
├── Nargo.toml # Project configuration
└── src/
├── main.nr # Main contract implementation
└── custom_note.nr # Custom note type definition