2025-10-07 21:20:00 +08:00
# Durable Nonce Guide
2025-09-19 00:49:45 +08:00
2025-10-07 21:20:00 +08:00
This guide explains how to use Durable Nonce in Sol Trade SDK to implement transaction replay protection and optimize transaction processing.
2025-09-19 00:49:45 +08:00
2025-10-07 21:20:00 +08:00
## 📋 What is Durable Nonce?
2025-09-19 00:49:45 +08:00
2025-10-07 21:20:00 +08:00
Durable Nonce is a Solana feature that allows you to create transactions that remain valid for extended periods, beyond the 150-block limitation of recent block hashes.
2025-09-19 00:49:45 +08:00
## 🚀 Core Benefits
2025-09-19 18:02:11 +08:00
- **Transaction Replay Protection**: Prevents identical transactions from being executed multiple times
2025-09-19 00:49:45 +08:00
- **Extended Time Window**: Transactions can remain valid for longer periods
2025-09-19 18:02:11 +08:00
- **Network Performance Optimization**: Reduces dependency on the latest block hash
2025-09-19 00:49:45 +08:00
- **Transaction Determinism**: Provides consistent transaction processing experience
- **Offline Transaction Support**: Supports offline processing of pre-signed transactions
## 🛠️ Implementation
### Prerequisites:
You need to create a nonce account for your payer account first.
Reference: https://solana.com/developers/guides/advanced/introduction-to-durable-nonces
2025-10-07 21:20:00 +08:00
### 1. Fetch Nonce Information
2025-09-19 00:49:45 +08:00
2025-10-07 21:20:00 +08:00
Directly fetch nonce information from RPC:
2025-09-19 00:49:45 +08:00
```rust
2025-10-07 21:20:00 +08:00
use sol_trade_sdk ::common ::nonce_cache ::fetch_nonce_info ;
use solana_sdk ::pubkey ::Pubkey ;
use std ::str ::FromStr ;
2025-09-19 00:49:45 +08:00
2025-09-19 18:02:11 +08:00
// Set up nonce account
2025-10-07 21:20:00 +08:00
let nonce_account = Pubkey ::from_str ( "your_nonce_account_address_here" ) ? ;
2025-09-19 00:49:45 +08:00
2025-10-07 21:20:00 +08:00
// Fetch nonce information
let durable_nonce = fetch_nonce_info ( & client . rpc , nonce_account ). await ;
2025-09-19 00:49:45 +08:00
```
2025-10-07 21:20:00 +08:00
### 2. Use Nonce in Transactions
2025-09-19 00:49:45 +08:00
2025-09-21 21:56:17 +08:00
Set nonce parameters: durable_nonce
2025-09-19 00:49:45 +08:00
```rust
let buy_params = sol_trade_sdk ::TradeBuyParams {
dex_type : DexType ::PumpFun ,
mint : mint_pubkey ,
sol_amount : buy_sol_amount ,
slippage_basis_points : Some ( 100 ),
2025-09-21 21:56:17 +08:00
recent_blockhash : Some ( recent_blockhash ),
2025-09-19 00:49:45 +08:00
extension_params : Box ::new ( PumpFunParams ::from_trade ( & trade_info , None )),
wait_transaction_confirmed : true ,
create_wsol_ata : false ,
close_wsol_ata : false ,
create_mint_ata : true ,
open_seed_optimize : false ,
2025-10-07 21:20:00 +08:00
durable_nonce : durable_nonce , // Set durable nonce
2025-09-19 00:49:45 +08:00
};
// Execute transaction
client . buy ( buy_params ). await ? ;
```
2025-10-07 21:20:00 +08:00
## 🔄 Nonce Usage Flow
2025-09-19 00:49:45 +08:00
2025-10-07 21:20:00 +08:00
1. **Fetch** : Get the latest nonce value from RPC
2. **Use** : Set nonce parameters in transactions
3. **Refresh** : Call `fetch_nonce_info` again before next use to get new nonce value
2025-09-19 00:49:45 +08:00
## 🔗 Related Documentation
2025-10-07 21:20:00 +08:00
- [Example: Durable Nonce ](../examples/nonce_cache/ )