Skip to main content

Using Address Note in Aztec.nr

Address notes hold one main property of the type AztecAddress. It also holds owner and randomness, similar to other note types.

AddressNote

This is the AddressNote:

address_note_def
#[note]
#[derive(Eq)]
pub struct AddressNote {
address: AztecAddress,
owner: AztecAddress,
randomness: Field,
}

impl AddressNote {
pub fn new(address: AztecAddress, owner: AztecAddress) -> Self {
// Safety: we use the randomness to preserve the privacy of the note recipient by preventing brute-forcing, so a
// malicious sender could use non-random values to make the note less private. But they already know the full
// note pre-image anyway, and so the recipient already trusts them to not disclose this information. We can
// therefore assume that the sender will cooperate in the random value generation.
let randomness = unsafe { random() };
AddressNote { address, owner, randomness }
}
}
Source code: noir-projects/aztec-nr/address-note/src/address_note.nr#L5-L24

Importing AddressNote

In Nargo.toml

address_note = { git="https://github.com/AztecProtocol/aztec-packages/", tag="v0.82.3", directory="noir-projects/aztec-nr/address-note" }

In your contract

addressnote_import
use dep::address_note::address_note::AddressNote;
Source code: noir-projects/noir-contracts/contracts/escrow_contract/src/main.nr#L14-L16

Working with AddressNote

Creating a new note

Creating a new AddressNote takes the following args:

  • address (AztecAddress): the address to store in the AddressNote
  • owner (AztecAddress): owner is the party whose nullifying key can be used to spend the note
addressnote_new
let note = AddressNote::new(owner, owner);
Source code: noir-projects/noir-contracts/contracts/escrow_contract/src/main.nr#L28-L30

In this example, owner is the address and the npk_m_hash of the donor was computed earlier.

Learn more