> Aztec.nr API reference, v6.0.0 (mainnet and testnet). Index: https://docs.aztec.network/aztec-nr-api/mainnet/llms.txt

# Struct NoteMessage

Module: `noir_aztec::note`

```rust
pub struct NoteMessage<Note>
{ /* private fields */ }
```

A message with information about a note that was created in the current contract call. This message **MUST** be delivered to a recipient in order to not lose the private note information.

Use [`NoteMessage::deliver`](/aztec-nr-api/mainnet/noir_aztec/note/struct.NoteMessage.md#deliver) to select a delivery mechanism. The same message can be delivered to multiple recipients.

## Implementations

```rust
impl<Note> NoteMessage<Note>
where
    Note: NoteType,
    Note: Packable<N = _>
```

```rust
pub fn new(new_note: NewNote<Note>, context: &mut PrivateContext) -> Self
where
    Note: Packable
```

```rust
pub fn deliver<D>(self, delivery_mode: D)
where
    D: MessageDeliveryBuilder,
    Note: Packable
```

Delivers the note message to its owner, providing them access to the private note information.

The message is first encrypted to the owner's public key, ensuring no other actor can read it.

The `delivery_mode` is produced by the [`crate::messages::delivery::MessageDelivery`](/aztec-nr-api/mainnet/noir_aztec/messages/delivery/struct.MessageDelivery.md) entrypoints (`offchain`, `onchain_unconstrained`, or `onchain_constrained`). It informs costs (both proving time and TX fees) as well as delivery guarantees, and must be a compile-time constant.

To deliver the message to a recipient that is not the note's owner, use [`deliver_to`](/aztec-nr-api/mainnet/noir_aztec/note/struct.NoteMessage.md#deliver_to) instead.

#### Invalid Recipients

If the note's owner is an invalid address, then a random public key is selected and message delivery continues as normal. This prevents both 'king of the hill' attacks (where a sender would otherwise fail to deliver a note to an invalid recipient) and forced privacy leaks (where an invalid recipient results in a unique transaction fingerprint, e.g. one lacking the private logs that would correspond to message delivery).

```rust
pub fn deliver_to<D>(self, recipient: AztecAddress, delivery_mode: D)
where
    D: MessageDeliveryBuilder,
    Note: Packable
```

Same as [`deliver`](/aztec-nr-api/mainnet/noir_aztec/note/struct.NoteMessage.md#deliver), except the message gets delivered to an arbitrary `recipient` instead of the note owner.

Note that `recipient` getting the message does not let them **use** the note, it only means that thy will know about it, including the transaction in which it was created, and prove it exists. They will also not be able to know when or if the note is used (i.e. nullified), assuming the standard note nullifier function.

#### Use Cases

This feature enables many design patterns that diverge in how notes are traditionally handled. For example, an institutional contract may require to have some actor receive all notes created for compliance purposes. Or a low value application like a game might deliver all notes offchain to a centralized server that then serves them via the app, bypassing the need for contract sync and improving UX.

```rust
pub fn get_note(self) -> Note
where
    Note: Packable
```

Returns the note contained in the message.

```rust
pub fn get_new_note(self) -> NewNote<Note>
where
    Note: Packable
```

Returns the [`NewNote`](/aztec-nr-api/mainnet/noir_aztec/note/lifecycle/struct.NewNote.md) container in the message.

This is an advanced function, typically needed only when creating new kinds of state variables that need to create [`MaybeNoteMessage`](/aztec-nr-api/mainnet/noir_aztec/note/struct.MaybeNoteMessage.md) values.
