feat: harden trading SDK examples
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
# Durable Nonce
|
||||
|
||||
[中文](README_CN.md)
|
||||
|
||||
Shows how to fetch a durable nonce and attach it to a PumpFun transaction triggered by a `sol-parser-sdk` gRPC event.
|
||||
|
||||
> This is a live-transaction template. Set `PRIVATE_KEY`, replace `use_your_nonce_account_here`, and configure RPC and gRPC before running. The nonce authority must match the signer.
|
||||
|
||||
```bash
|
||||
export GRPC_ENDPOINT=https://your-yellowstone.example
|
||||
export GRPC_AUTH_TOKEN=optional-token
|
||||
cargo run --package nonce_cache
|
||||
```
|
||||
|
||||
Do not set both a recent blockhash and a durable nonce in new code; use `SimpleBuyParams::with_durable_nonce`. Refresh nonce state immediately before construction, and never reuse consumed nonce state. A nonce extends transaction validity but does not preserve quote freshness.
|
||||
|
||||
See [Nonce Cache](../../docs/NONCE_CACHE.md).
|
||||
@@ -0,0 +1,17 @@
|
||||
# Durable Nonce
|
||||
|
||||
[English](README.md)
|
||||
|
||||
展示如何获取 durable nonce,并附加到由 `sol-parser-sdk` gRPC 事件触发的 PumpFun 交易。
|
||||
|
||||
> 这是会发送真实交易的模板。运行前设置 `PRIVATE_KEY`,替换 `use_your_nonce_account_here`,并配置 RPC 和 gRPC;nonce authority 必须与签名者匹配。
|
||||
|
||||
```bash
|
||||
export GRPC_ENDPOINT=https://your-yellowstone.example
|
||||
export GRPC_AUTH_TOKEN=optional-token
|
||||
cargo run --package nonce_cache
|
||||
```
|
||||
|
||||
新代码不要同时设置 recent blockhash 和 durable nonce,应使用 `SimpleBuyParams::with_durable_nonce`。构建前刷新 nonce,已消费状态不可复用。Nonce 只延长交易有效期,不会保持报价新鲜。
|
||||
|
||||
参见[Nonce Cache 说明](../../docs/NONCE_CACHE_CN.md)。
|
||||
@@ -23,7 +23,7 @@ use sol_trade_sdk::{
|
||||
SolanaTrade,
|
||||
};
|
||||
use solana_commitment_config::CommitmentConfig;
|
||||
use solana_sdk::{pubkey::Pubkey, signature::Keypair};
|
||||
use solana_sdk::pubkey::Pubkey;
|
||||
|
||||
static ALREADY_EXECUTED: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
@@ -104,7 +104,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
async fn create_solana_trade_client() -> AnyResult<SolanaTrade> {
|
||||
println!("🚀 Initializing SolanaTrade client...");
|
||||
let payer = Keypair::from_base58_string("use_your_payer_keypair_here");
|
||||
let payer = sol_trade_sdk::common::keypair::load_keypair_from_env("PRIVATE_KEY")?;
|
||||
let rpc_url = "https://api.mainnet-beta.solana.com".to_string();
|
||||
let commitment = CommitmentConfig::confirmed();
|
||||
let swqos_configs: Vec<SwqosConfig> = vec![SwqosConfig::Default(rpc_url.clone())];
|
||||
|
||||
Reference in New Issue
Block a user