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

# Struct SingleUseClaim

Module: `noir_aztec::state_vars`

```rust
pub struct SingleUseClaim<Context>
{ /* private fields */ }
```

Private right to perform an action.

A private state variable type that represents a right each user can exercise at most once.

Because it is *owned*, you must wrap a [`SingleUseClaim`](/aztec-nr-api/v6.0.0/noir_aztec/state_vars/struct.SingleUseClaim.md) inside an [`crate::state_vars::owned::Owned`](/aztec-nr-api/v6.0.0/noir_aztec/state_vars/struct.Owned.md) state variable when using it in storage.

## Example

The right to vote at most once can be implemented using [`SingleUseClaim`](/aztec-nr-api/v6.0.0/noir_aztec/state_vars/struct.SingleUseClaim.md) as a primitive.

```rust
#[derive(Serialize, Deserialize)]
struct ElectionId { id: Field }

#[storage]
struct Storage<Context> {
    // election => candidate => number of votes
    tally: Map<ElectionId, Map<Field, PublicMutable<Field, Context>, Context>, Context>,
    // track right to vote at most once per election
    vote_claims: Map<ElectionId, Owned<SingleUseClaim<Context>, Context>, Context>,
}

#[external("private")]
fn cast_vote(election_id: ElectionId, candidate: Field) {
    let voter = self.msg_sender();

    // `claim` will only succeed if `voter` hasn't already claimed for this `election_id` before.
    self.storage.vote_claims.at(election_id).at(voter).claim();

    // Now that we checked that the voter is entitled to vote,
    // we can enqueue the corresponding public effect
    self.enqueue_self.add_to_tally_public(election_id, candidate);
}
```

For more details on what *owned* means, see the documentation for the [`OwnedStateVariable`](/aztec-nr-api/v6.0.0/noir_aztec/state_vars/trait.OwnedStateVariable.md) trait.

## Cost

Exercising a claim (via the [`SingleUseClaim::claim`](/aztec-nr-api/v6.0.0/noir_aztec/state_vars/struct.SingleUseClaim.md#claim) function) emits one nullifier.

## Privacy considerations

The [`SingleUseClaim::claim`](/aztec-nr-api/v6.0.0/noir_aztec/state_vars/struct.SingleUseClaim.md#claim) function emits a public nullifier per owner: it's fully private, hidden behind the owner's app-siloed nullifier hiding key (aka `nhk`).

Public effects you emit alongside a claim (e.g. a public function call to update a tally) may still let observers infer who likely exercised the claim, so consider that when designing flows.

## Implementations

```rust
impl<Context> SingleUseClaim<Context>
```

```rust
impl SingleUseClaim<&mut PrivateContext>
```

```rust
pub fn claim(self)
```

Records the fact that the owner in scope has claimed this single use claim.

This function succeeds at most once for a given `owner`. Any subsequent calls with same owner are guaranteed to fail.

Note that, by itself, calling this function doesn't do anything other than prevent it being called again with the same owner. Its invocation is typically accompanied by other contract actions, e.g. minting tokens, casting a vote, etc.

#### Advanced

The implementation of this function emits a nullifier derived from the `owner`'s nullifier hiding key and the storage slot of the underlying state variable.

```rust
pub fn assert_claimed(self)
```

Asserts that the owner has already claimed this single use claim (i.e. that [`SingleUseClaim::claim`](/aztec-nr-api/v6.0.0/noir_aztec/state_vars/struct.SingleUseClaim.md#claim) has been called).

#### Advanced

This function generates a kernel nullifier read request, so it can even assert the existence of pending claims, i.e. when [`SingleUseClaim::claim`](/aztec-nr-api/v6.0.0/noir_aztec/state_vars/struct.SingleUseClaim.md#claim) was called in the same transaction as [`SingleUseClaim::assert_claimed`](/aztec-nr-api/v6.0.0/noir_aztec/state_vars/struct.SingleUseClaim.md#assert_claimed).

```rust
impl SingleUseClaim<UtilityContext>
```

```rust
pub unconstrained fn has_claimed(self) -> bool
```

Returns `true` if an owner has claimed this single use claim.

## Trait implementations

```rust
impl<Context> OwnedStateVariable<Context> for SingleUseClaim<Context>
```

```rust
pub fn new(context: Context, storage_slot: Field, owner: AztecAddress) -> Self
```
