Rust example: PumpSwap outer AMM buy → wait ~30s → sell (1 round by default; see src/run.rs). Encrypted keystore + multi-SWQoS.
This crate uses
sol-safekey 0.1.8from crates.io andsol-trade-sdk 4.0.22. No local../sol-safekeycheckout is required.
中文 | English | Website | Telegram | Discord
- Automated Trading Loop: Buy → wait ~30s → sell; 1 round by default (
ROUNDS,REST_SECSinsrc/run.rs) - Multiple SWQoS Support: Send transactions concurrently to multiple MEV protection services
- Durable Nonce: Transaction replay protection for multi-SWQoS scenarios
- Flexible Configuration: Support for both YAML config files and environment variables
- Environment Priority: Environment variables override config file settings for sensitive data
- Cross-Platform Build: Build scripts for Linux deployment
- Explicit Trade Intent: Buy uses
SimpleBuyParams + BuyAmount::WithMaxInput; sell usesSellAmount::ExactInput. Buy and sell slippage default to 500 bps (5%).
git clone https://github.com/0xfnzero/fnzero-examples.git
cd fnzero-examples/pumpswap_trade_with_safekeyEnsure you have Rust and Cargo installed:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh- Install the optional
sol-safekeyCLI to createkeystore.json; Cargo downloads the library dependency automatically. - In this crate:
cp .env.example .env
cp config/dev/solana.yaml.example config/dev/solana.yaml
cp config/dev/trading.yaml.example config/dev/trading.yamlDo not commit .env, filled YAML, or keystore.json.
Create a .env file based on .env.example:
# Environment: dev or prod
APP_ENV=prod
# Token mint address (can also be passed as CLI argument)
MINT=
# Keystore password (optional, interactive if not set)
KEYSTORE_PASSWORD=
# RPC URL
SOLANA_RPC_URL=http://your-rpc-endpoint.com
# Buy amount in SOL
BUY_SOL_AMOUNT=0.01
# SWQoS region
SWQOS_REGION=Frankfurt
# SWQoS provider tokens
SWQOS_ASTRALANE_TOKEN=
SWQOS_BLOCKRAZOR_TOKEN=
SWQOS_JITO_TOKEN=
SWQOS_ZEROSLOT_TOKEN=
# ... etc.
# Durable nonce account (required when using 2+ SWQoS)
NONCE_ACCOUNT=This guide will walk you through setting up everything using sol-safekey, including creating keystore.json, unlocking the wallet, creating WSOL ATA, and creating durable nonce accounts.
Install from crates.io (Recommended):
cargo install sol-safekey --version 0.1.8 --features full --locked
sol-safekey --versionInstall a local development checkout:
cargo install --path /path/to/sol-safekey --features full --lockedsol-safekey startYou will see the language selection screen:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Sol-SafeKey - Solana Security Key Management Tool
Solana 密钥管理工具
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Please select language | 请选择语言:
1. 中文
2. English
Select language (1-2): _
Enter 2 to select English.
After selecting language, you'll see the main menu:
==================================================
Sol-SafeKey - Solana Key Management Tool
==================================================
Core Functions (3 operations):
1. Create Plaintext Key
2. Create Encrypted Key (bot)
3. Decrypt Key
🔒 Wallet Status: Unlocked
U. Unlock Wallet (for Solana Operations)
Advanced Security Features:
4. Setup 2FA Authentication
5. Generate Triple-Factor Wallet
6. Unlock Triple-Factor Wallet
Solana On-Chain Operations:
7. Check SOL Balance
8. Transfer SOL
9. Create WSOL ATA
10. Wrap SOL → WSOL
11. Unwrap WSOL → SOL
12. Close WSOL ATA
13. Transfer SPL Token
14. Create Nonce Account
15. Pump.fun Sell Token
16. PumpSwap Sell Token
17. Pump.fun Cashback (View & Claim)
18. PumpSwap Cashback (View & Claim)
0. Exit
Select operation (0-18/U): _
Important Note: Since you haven't created a wallet yet, you need to unlock wallet or create a new wallet first.
Steps to Create New Wallet:
- Select
1. Create Plaintext Key - Follow prompts to generate keypair
- Follow prompts to save to file
Steps to Encrypt Existing Key:
- Select
2. Create Encrypted Key - Enter or paste existing private key
- Enter password when prompted
- Enter password to confirm
- Select filename to save (default: keystore.json)
Steps to Unlock Wallet:
- Select
UUnlock Wallet - Enter keystore file path when prompted (default: keystore.json)
- Enter password
- After unlock, wallet is stored in session for Solana operations
Example Output:
Unlock Wallet
Keystore file path [keystore.json]:
Enter password: ********
✅ Wallet unlocked successfully!
📍 Current Wallet: 7xKm...9xW3
After unlocking wallet, you need to create a WSOL Associated Token Account. However, WSOL ATA is automatically created during the first buy operation, so you don't need to manually create it.
If you want to create it manually for testing:
- From the main menu, enter the Solana operations
- Select "Create WSOL ATA"
- System will automatically create WSOL ATA
Note: For the pumpswap_trade_with_safekey example, WSOL ATA is automatically created during the first buy operation, so manual setup is not required.
Create a nonce account for transaction replay protection (required when using 2+ SWQoS services):
- From Solana operations menu, select "Create Nonce Account"
- System will create a new nonce account
- Wait for transaction confirmation
- Important: Save the created nonce account address for configuration
Example Output:
🚀 Creating Nonce Account...
✅ Nonce account created and initialized successfully!
📍 Address: 5xKm...7xW3
🔐 Nonce value: 1234abcd...efgh5678
💡 Please save this Nonce account address for future use!
Add the nonce account address created above to your configuration file:
# config/dev/solana.yaml or config/prod/solana.yaml
nonce_config:
buy_nonce_accounts:
- "5xKm...7xW3" # Use the actual created address
sell_nonce_accounts:
- "5xKm...7xW3" # Can use the same, or create different onesNotes:
- WSOL ATA is automatically created during the first buy operation, no manual setup required
- When using 2 or more SWQoS services, durable nonce accounts are required
- You can use separate nonce accounts for buy and sell operations, or use the same one
Configuration is organized in config/ directory:
config/
├── dev/
│ ├── solana.yaml # RPC, keystore, SWQoS, nonce config
│ └── trading.yaml # Trading parameters, gas fee settings
└── prod/
├── solana.yaml
└── trading.yaml
Environment Variables Override:
- All sensitive values in config files can be overridden by environment variables
.envvalues have higher priority than config files- Useful for keeping secrets out of version control
The following SWQoS services are supported:
| Service | Required Param |
|---|---|
| Astralane | API Key |
| BlockRazor | API Key |
| Jito | UUID |
| NextBlock | API Key |
| Bloxroute | API Key |
| ZeroSlot | API Key |
| Temporal | API Key |
| FlashBlock | API Key |
| Node1 | API Key |
Apply for API keys at: https://fnzero.dev/swqos
Simply run the script:
./run.shThe script will:
- Load configuration from
.envandconfig/dev/solana.yaml - Prompt for keystore password (unless
KEYSTORE_PASSWORDis set) - Build and run the trading bot in release mode
- Support dev/prod environments via
APP_ENVvariable
./pumpswap_trade_with_safekey <MINT_ADDRESS>MINT=<MINT_ADDRESS> ./pumpswap_trade_with_safekey# Set MINT in .env or pass as argument
./pumpswap_trade_with_safekeyAPP_ENV=prod ./pumpswap_trade_with_safekey <MINT_ADDRESS>cargo build --release
# Binary: build-cache/release/pumpswap_trade_with_safekey./build-linux-release.shThis script:
- Cross-compiles for Linux (x86_64-unknown-linux-gnu)
- Packages binary and configs into
linux-release/deploy.tar.gz
Output:
linux-release/
├── x86_64-unknown-linux-gnu/release/pumpswap_trade_with_safekey
└── deploy.tar.gz
MIT License
- Official Website: https://fnzero.dev/
- Project Repository: https://github.com/0xfnzero/fnzero-examples
- Telegram Group: https://t.me/fnzero_group
- Discord: https://discord.gg/vuazbGkqQE