> ## Documentation Index
> Fetch the complete documentation index at: https://solana.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# Durable Nonces

> How durable nonces work on Solana for offline signing and delayed transaction submission, including nonce lifecycle, detection, validation, and failure behavior.

<Info>
  **Summary**

  Durable nonce transactions replace the recent blockhash with a stored nonce
  value, removing the 150 slot expiry window for a transaction. This enables
  offline signing and delayed submission.
</Info>

<Warning>
  Durable nonces may be deprecated in a future release. See [SIMD
  discussion](https://github.com/solana-foundation/solana-improvement-documents/discussions/415)
  for details.
</Warning>

## Durable nonces

A durable nonce transaction replaces the recent blockhash with a stored nonce
value, removing the 150 slot expiry window. This enables offline signing and
delayed submission.

### How nonce transactions work

A nonce account is a System Program-owned account that stores a
`State::Initialized` value containing three fields: an **authority** pubkey
(who can advance the nonce), a **durable nonce** value (a hash derived from a
recent blockhash), and **lamports per signature** (the fee rate when the nonce
was last advanced).

To use a durable nonce:

1. Create and initialize a nonce account using `CreateAccount` +
   `InitializeNonceAccount`
2. Build the transaction with `AdvanceNonceAccount` as the **first
   instruction** and the nonce value as the `recent_blockhash`
3. Sign the transaction (can be done offline, since the nonce does not expire)
4. Submit when ready

### Create and use a nonce account

This example creates a nonce account, reads its stored nonce, and uses that
nonce to send a SOL transfer. It uses a local validator so the payer can be
funded automatically.

```ts title="Durable nonce transfer"
import {
  appendTransactionMessageInstructions,
  assertIsTransactionWithBlockhashLifetime,
  assertIsTransactionWithDurableNonceLifetime,
  createClient,
  createTransactionMessage,
  generateKeyPairSigner,
  getSignatureFromTransaction,
  lamports,
  type Nonce,
  pipe,
  sendAndConfirmDurableNonceTransactionFactory,
  sendAndConfirmTransactionFactory,
  setTransactionMessageFeePayerSigner,
  setTransactionMessageLifetimeUsingBlockhash,
  setTransactionMessageLifetimeUsingDurableNonce,
  signTransactionMessageWithSigners,
} from "@solana/kit";
import { rpcAirdrop, solanaRpc } from "@solana/kit-plugin-rpc";
import { airdropPayer, payer } from "@solana/kit-plugin-signer";
import {
  fetchNonce,
  getCreateAccountInstruction,
  getInitializeNonceAccountInstruction,
  getNonceSize,
  getTransferSolInstruction,
  SYSTEM_PROGRAM_ADDRESS,
} from "@solana-program/system";

const feePayer = await generateKeyPairSigner();
const recipient = await generateKeyPairSigner();
const nonceAccount = await generateKeyPairSigner();

const client = await createClient()
  .use(payer(feePayer))
  .use(
    solanaRpc({
      rpcUrl: "http://localhost:8899",
      rpcSubscriptionsUrl: "ws://localhost:8900",
    }),
  )
  .use(rpcAirdrop())
  .use(airdropPayer(lamports(1_000_000_000n)));

// Create and initialize the nonce account with a normal recent blockhash.
const nonceAccountSize = BigInt(getNonceSize());
const nonceAccountRent = await client.rpc
  .getMinimumBalanceForRentExemption(nonceAccountSize)
  .send();
const { value: latestBlockhash } = await client.rpc.getLatestBlockhash().send();

const createNonceMessage = pipe(
  createTransactionMessage({ version: "legacy" }),
  (message) => setTransactionMessageFeePayerSigner(feePayer, message),
  (message) =>
    setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, message),
  (message) =>
    appendTransactionMessageInstructions(
      [
        getCreateAccountInstruction({
          payer: feePayer,
          newAccount: nonceAccount,
          lamports: nonceAccountRent,
          space: nonceAccountSize,
          programAddress: SYSTEM_PROGRAM_ADDRESS,
        }),
        getInitializeNonceAccountInstruction({
          nonceAccount: nonceAccount.address,
          nonceAuthority: feePayer.address,
        }),
      ],
      message,
    ),
);

const createNonceTransaction =
  await signTransactionMessageWithSigners(createNonceMessage);
assertIsTransactionWithBlockhashLifetime(createNonceTransaction);
await sendAndConfirmTransactionFactory({
  rpc: client.rpc,
  rpcSubscriptions: client.rpcSubscriptions,
})(createNonceTransaction, { commitment: "confirmed" });

// Fetch the stored nonce, then use it instead of a recent blockhash.
const { data: nonceData } = await fetchNonce(client.rpc, nonceAccount.address);
const transferInstruction = getTransferSolInstruction({
  source: feePayer,
  destination: recipient.address,
  amount: lamports(1_000_000n),
});

const durableNonceMessage = pipe(
  createTransactionMessage({ version: "legacy" }),
  (message) => setTransactionMessageFeePayerSigner(feePayer, message),
  (message) =>
    setTransactionMessageLifetimeUsingDurableNonce(
      {
        nonce: nonceData.blockhash as string as Nonce,
        nonceAccountAddress: nonceAccount.address,
        nonceAuthorityAddress: nonceData.authority,
      },
      message,
    ),
  (message) =>
    appendTransactionMessageInstructions([transferInstruction], message),
);

const durableNonceTransaction =
  await signTransactionMessageWithSigners(durableNonceMessage);
assertIsTransactionWithDurableNonceLifetime(durableNonceTransaction);

await sendAndConfirmDurableNonceTransactionFactory({
  rpc: client.rpc,
  rpcSubscriptions: client.rpcSubscriptions,
})(durableNonceTransaction, { commitment: "confirmed" });

console.log(
  "Transaction signature:",
  getSignatureFromTransaction(durableNonceTransaction),
);
```

`setTransactionMessageLifetimeUsingDurableNonce` sets the stored nonce as the
transaction lifetime and prepends the required `AdvanceNonceAccount`
instruction. Add the transaction's other instructions after applying the durable
nonce lifetime so the advance instruction remains first.

After this transaction is processed, the nonce account contains a new value.
Refetch the account before building another transaction; a transaction signed
with the previous nonce cannot be submitted again.

### Nonce detection

The runtime detects nonce transactions by checking whether the first instruction
(index
[`NONCED_TX_MARKER_IX_INDEX`](https://github.com/anza-xyz/agave/blob/v3.1.8/svm-transaction/src/svm_message.rs#L20)
= 0) is a call to the System Program with the `AdvanceNonceAccount`
instruction. The nonce account must be the first account of that instruction and
must be writable. See
[`get_durable_nonce`](https://github.com/anza-xyz/agave/blob/v3.1.8/svm-transaction/src/svm_message.rs#L89-L121).

### Nonce validation flow

When a transaction's `recent_blockhash` is not found in the `BlockhashQueue`,
the validator checks if it is a valid nonce transaction via
[`check_transaction_age`](https://github.com/anza-xyz/agave/blob/v3.1.8/runtime/src/bank/check_transactions.rs#L152-L180):

1. The nonce's stored `durable_nonce` must differ from the next durable nonce
   (derived from the current blockhash). This ensures the nonce has not already
   been used in this block
2. The nonce account must be loaded and must parse as `State::Initialized`
3. The stored `durable_nonce` must match the transaction's `recent_blockhash`

The nonce authority signing check is performed later
([`validate_transaction_nonce`](https://github.com/anza-xyz/agave/blob/v3.1.8/svm/src/transaction_processor.rs#L676-L729)).

If all checks pass, the nonce is advanced to the next durable nonce value before
execution begins. On execution failure, the advanced nonce and the fee-deducted
fee payer are still committed (preventing replay while collecting fees).

### Nonce failure behavior

If a nonce transaction **fails validation** (nonce already used, authority not
signed, account not found), the entire transaction is dropped. No fees
collected, no state changes.

If a nonce transaction **passes validation but execution fails** (an instruction
returns an error), the nonce is still advanced and fees are still collected.
This prevents the transaction from being replayed while ensuring the validator
is compensated.
