Shred Delivery and Sender are now live! Get earliest access to raw Solana data and optimized transaction sending. Learn about Shred Delivery | Learn about Sender
简体中文
为 Solana 交易估算最佳优先费用。通过六个优先级别的实时费用分析,确保快速确认和成本效率。
最低 (Min)
低 (Low)
中等 (推荐) (Medium)
高 (High)
非常高 (VeryHigh)
不安全的最高值 (UnsafeMax)
import { Transaction, SystemProgram, ComputeBudgetProgram } from "@solana/web3.js"; import bs58 from "bs58"; // 1. Build your transaction (without priority fee) const transaction = new Transaction(); const transferIx = SystemProgram.transfer({ fromPubkey: senderKeypair.publicKey, toPubkey: recipientPublicKey, lamports: 1000000, // 0.001 SOL }); transaction.add(transferIx); // 2. Set required fields and serialize transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash; transaction.feePayer = senderKeypair.publicKey; const serializedTx = bs58.encode(transaction.serialize()); // 3. Get priority fee estimate const response = await fetch("https://mainnet.helius-rpc.com/?api-key=YOUR_API_KEY", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ jsonrpc: "2.0", id: "1", method: "getPriorityFeeEstimate", params: [{ transaction: serializedTx, options: { priorityLevel: "Medium", recommended: true } }] }) }); const result = await response.json(); const priorityFee = result.result.priorityFeeEstimate; // 4. Add priority fee and send transaction.instructions = []; // Reset transaction.add(ComputeBudgetProgram.setComputeUnitPrice({ microLamports: priorityFee })); transaction.add(transferIx); transaction.recentBlockhash = (await connection.getLatestBlockhash()).blockhash; transaction.sign(senderKeypair);
getRecentPerformanceSamples
此页面对您有帮助吗?