|
| 1 | +# Custom Note Contract |
| 2 | + |
| 3 | +An Aztec Noir contract demonstrating how to create and use custom note types in the Aztec protocol. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +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. |
| 8 | + |
| 9 | +## Custom Note Structure |
| 10 | + |
| 11 | +The `CustomNote` contains: |
| 12 | + |
| 13 | +- **a, b, c, d**: Four arbitrary `Field` values for custom data |
| 14 | +- **randomness**: A random `Field` value to ensure note privacy |
| 15 | +- **owner**: The `AztecAddress` of the note owner |
| 16 | + |
| 17 | +## Contract Functions |
| 18 | + |
| 19 | +### `insert(a: Field, b: Field, c: Field, d: Field)` |
| 20 | + |
| 21 | +A private function that creates and stores a new custom note. |
| 22 | + |
| 23 | +- **Parameters**: Four field values (a, b, c, d) |
| 24 | +- **Behavior**: Creates a note with the provided values and assigns ownership to the message sender |
| 25 | +- **Privacy**: Emits the note using unconstrained onchain message delivery |
| 26 | + |
| 27 | +### `view_custom_notes(owner: AztecAddress)` |
| 28 | + |
| 29 | +An unconstrained utility function to view all custom notes for a given owner. |
| 30 | + |
| 31 | +- **Parameters**: Owner's Aztec address |
| 32 | +- **Returns**: Array of custom notes (up to `MAX_NOTES_PER_PAGE`) |
| 33 | +- **Usage**: Can be called to query notes without consuming gas |
| 34 | + |
| 35 | +## Building |
| 36 | + |
| 37 | +Compile the contract using Nargo: |
| 38 | + |
| 39 | +```bash |
| 40 | +nargo compile |
| 41 | +``` |
| 42 | + |
| 43 | +## Usage Example |
| 44 | + |
| 45 | +1. **Deploy the contract** to an Aztec network |
| 46 | + |
| 47 | +2. **Insert a custom note**: |
| 48 | + |
| 49 | + ```noir |
| 50 | + CustomNote.insert(field1, field2, field3, field4) |
| 51 | + ``` |
| 52 | + |
| 53 | +3. **View notes for an address**: |
| 54 | + ```noir |
| 55 | + CustomNote.view_custom_notes(owner_address) |
| 56 | + ``` |
| 57 | + |
| 58 | +## Key Features |
| 59 | + |
| 60 | +- Demonstrates custom note type implementation with the `#[note]` macro |
| 61 | +- Shows how to use `PrivateSet` storage for managing multiple notes per user |
| 62 | +- Implements proper note privacy using randomness |
| 63 | +- Provides getter methods for accessing individual note fields |
| 64 | + |
| 65 | +## Dependencies |
| 66 | + |
| 67 | +- Aztec Noir v3.0.0-nightly.20251107 |
| 68 | +- Nargo >= 1.0.0 |
| 69 | + |
| 70 | +## Project Structure |
| 71 | + |
| 72 | +``` |
| 73 | +custom-note/ |
| 74 | +├── Nargo.toml # Project configuration |
| 75 | +└── src/ |
| 76 | + ├── main.nr # Main contract implementation |
| 77 | + └── custom_note.nr # Custom note type definition |
| 78 | +``` |
| 79 | + |
| 80 | +## Learn More |
| 81 | + |
| 82 | +- [Aztec Documentation](https://docs.aztec.network/) |
| 83 | +- [Noir Language Documentation](https://noir-lang.org/) |
0 commit comments