sendTransaction RPC Method
You can protect your transactions from toxic MEV threats like sandwich attacks and front-running by enabling MEV protection. To know more on how to enable it, check out our MEV Protection documentation. For an in-depth guide on MEV, see What is MEV (Maximum Extractable Value) and How to Protect Your Transactions on Solana.
用途 sendTransaction when you want a single RPC call that:
- broadcasts your signed transaction
- optionally runs preflight simulation to catch common failures
- optionally retries submission during congestion
該標準 sendTransaction RPC method available through our Core API provides reliable transaction submission through Quicknode's globally distributed infrastructure. sendTransaction leverages our optimized node architecture to propagate your transaction to the Solana network efficiently.
Stake-Weighted Quality of Service (SWQoS) applies when transaction best practices are followed, as outlined in Quicknode’s Solana transaction guidelines.
Best for: General-purpose applications, development environments, and standard dApp operations where consistent, reliable performance is needed without specialized requirements.
參數
transaction
字串
載入中...
物件
物件
載入中...
skipPreflight
布林值
載入中...
preflightCommitment
字串
載入中...
encoding
字串
載入中...
maxRetries
usize
載入中...
minContextSlot
整數
載入中...
退貨
結果
載入中...
請求
1curl https://docs-demo。solana-mainnet.quiknode.pro/ \2-X POST \3-H "Content-Type: application/json" \4--data '{"method":"sendTransaction","params":["ENTER_ENCODED_TRANSACTION_ID"],"id":1,"jsonrpc":"2.0"}'
1curl https://docs-demo。solana-mainnet.quiknode.pro/ \2-X POST \3-H "Content-Type: application/json" \4--data '{"method":"sendTransaction","params":["ENTER_ENCODED_TRANSACTION_ID"],"id":1,"jsonrpc":"2.0"}'
1需要 "uri"2require "json"3需要 "net/http"45網址 = URI("https://docs-demo.solana-mainnet.quiknode.pro/")67https = 網::HTTP.new(url.主機, 網址.port)8https.use_ssl = true910請求 = 淨額::HTTP::POST.新增(網址)11請求["Content-Type"] = "application/json"12請求。主體 = JSON.dump({13"method": "sendTransaction",14"params": [15"ENTER_ENCODED_TRANSACTION_ID"16],17"id": 1,18"jsonrpc": "2.0"19})2021回應 = https.請求(請求)22puts 回應。read_body23
1需要 "uri"2require "json"3需要 "net/http"45網址 = URI("https://docs-demo.solana-mainnet.quiknode.pro/")67https = 網::HTTP.new(url.主機, 網址.port)8https.use_ssl = true910請求 = 淨額::HTTP::POST.新增(網址)11請求["Content-Type"] = "application/json"12請求。主體 = JSON.dump({13"method": "sendTransaction",14"params": [15"ENTER_ENCODED_TRANSACTION_ID"16],17"id": 1,18"jsonrpc": "2.0"19})2021回應 = https.請求(請求)22puts 回應。read_body23
1import {2createSolanaRpc,3generateKeyPairSigner,4lamports,5sendAndConfirmTransactionFactory,6pipe,7createTransactionMessage,8setTransactionMessageFeePayer,9setTransactionMessageLifetimeUsingBlockhash,10appendTransactionMessageInstruction,11signTransactionMessageWithSigners,12getSignatureFromTransaction,13} from "@solana/kit";14import { getTransferSolInstruction } from "@solana-program/system";1516const LAMPORTS_PER_SOL = BigInt(1_000_000_000);1718(async () => {19try {2021const rpc = createSolanaRpc("https://docs-demo.solana-mainnet.quiknode.pro/");2223// 2 - Generate signers24const user1 = await generateKeyPairSigner();25console.log(`✅ - New user1 address created: ${user1.address}`);2627const user2 = await generateKeyPairSigner();28console.log(`✅ - New user2 address created: ${user2.address}`);2930// 3 - Airdrop SOL to user131const airdropTx = await rpc.requestAirdrop(32user1.address,33lamports(LAMPORTS_PER_SOL),34{ commitment: 'processed' }35).send();36console.log(`✅ - Airdropped 1 SOL to user1. Transaction: ${airdropTx}`);3738// 4 - Create transfer transaction39const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();40const transactionMessage = pipe(41createTransactionMessage({ version: 0 }),42tx => setTransactionMessageFeePayer(user1.address, tx),43tx => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),44tx => appendTransactionMessageInstruction(45getTransferSolInstruction({46amount: lamports(LAMPORTS_PER_SOL / BigInt(2)),47destination: user2.address,48source: user1,49}),50tx51)52);5354// 5 - Sign and send transaction55const signedTransaction = await signTransactionMessageWithSigners(transactionMessage);56const sendAndConfirmTransaction = sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions });5758await sendAndConfirmTransaction(59signedTransaction,60{ commitment: 'confirmed', skipPreflight: true }61);6263const signature = getSignatureFromTransaction(signedTransaction);64console.log(`✅ - Transfer transaction signature: ${signature}`);65} catch (error) {66console.error('Error occurred:', error);67}68})();69
1import {2createSolanaRpc,3generateKeyPairSigner,4lamports,5sendAndConfirmTransactionFactory,6pipe,7createTransactionMessage,8setTransactionMessageFeePayer,9setTransactionMessageLifetimeUsingBlockhash,10appendTransactionMessageInstruction,11signTransactionMessageWithSigners,12getSignatureFromTransaction,13} from "@solana/kit";14import { getTransferSolInstruction } from "@solana-program/system";1516const LAMPORTS_PER_SOL = BigInt(1_000_000_000);1718(async () => {19try {2021const rpc = createSolanaRpc("https://docs-demo.solana-mainnet.quiknode.pro/");2223// 2 - Generate signers24const user1 = await generateKeyPairSigner();25console.log(`✅ - New user1 address created: ${user1.address}`);2627const user2 = await generateKeyPairSigner();28console.log(`✅ - New user2 address created: ${user2.address}`);2930// 3 - Airdrop SOL to user131const airdropTx = await rpc.requestAirdrop(32user1.address,33lamports(LAMPORTS_PER_SOL),34{ commitment: 'processed' }35).send();36console.log(`✅ - Airdropped 1 SOL to user1. Transaction: ${airdropTx}`);3738// 4 - Create transfer transaction39const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();40const transactionMessage = pipe(41createTransactionMessage({ version: 0 }),42tx => setTransactionMessageFeePayer(user1.address, tx),43tx => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),44tx => appendTransactionMessageInstruction(45getTransferSolInstruction({46amount: lamports(LAMPORTS_PER_SOL / BigInt(2)),47destination: user2.address,48source: user1,49}),50tx51)52);5354// 5 - Sign and send transaction55const signedTransaction = await signTransactionMessageWithSigners(transactionMessage);56const sendAndConfirmTransaction = sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions });5758await sendAndConfirmTransaction(59signedTransaction,60{ commitment: 'confirmed', skipPreflight: true }61);6263const signature = getSignatureFromTransaction(signedTransaction);64console.log(`✅ - Transfer transaction signature: ${signature}`);65} catch (error) {66console.error('Error occurred:', error);67}68})();69
1const web3 = require("@solana/web3.js");2(async () => {3const solana = new web3.Connection("https://docs-demo.solana-mainnet.quiknode.pro/");4// Replace fromWallet with your public/secret keypair, wallet must have funds to pay transaction fees.5const fromWallet = web3.Keypair.generate();6const toWallet = web3.Keypair.generate();7const transaction = new web3.Transaction().add(8web3.SystemProgram.transfer({9fromPubkey: fromWallet.publicKey,10toPubkey: toWallet.publicKey,11lamports: web3.LAMPORTS_PER_SOL / 100,12})13);14console.log(await solana.sendTransaction(transaction, [fromWallet]));15})();16
1const web3 = require("@solana/web3.js");2(async () => {3const solana = new web3.Connection("https://docs-demo.solana-mainnet.quiknode.pro/");4// Replace fromWallet with your public/secret keypair, wallet must have funds to pay transaction fees.5const fromWallet = web3.Keypair.generate();6const toWallet = web3.Keypair.generate();7const transaction = new web3.Transaction().add(8web3.SystemProgram.transfer({9fromPubkey: fromWallet.publicKey,10toPubkey: toWallet.publicKey,11lamports: web3.LAMPORTS_PER_SOL / 100,12})13);14console.log(await solana.sendTransaction(transaction, [fromWallet]));15})();16
1from solana.rpc.api import Client2from solana.account import Account3from solana.system_program import TransferParams, transfer4from solana.transaction import Transaction5#Make sure to paste sender, reciever addresses and public key.6solana_client = Client("https://docs-demo.solana-mainnet.quiknode.pro/")7sender, reciever = Account(1), Account(2)8json_request = solana_client.get_recent_blockhash()9recent_blockhash = json_request["result"]["value"]["blockhash"]10txn = Transaction(fee_payer=sender.public_key(), recent_blockhash=recent_blockhash)11txn.add(12transfer(13TransferParams(14from_pubkey=sender.public_key(),15to_pubkey=reciever.public_key(),16lamports=100017)18)19)20txn.sign(sender)21print(solana_client.send_transaction(txn, sender))
1from solana.rpc.api import Client2from solana.account import Account3from solana.system_program import TransferParams, transfer4from solana.transaction import Transaction5#Make sure to paste sender, reciever addresses and public key.6solana_client = Client("https://docs-demo.solana-mainnet.quiknode.pro/")7sender, reciever = Account(1), Account(2)8json_request = solana_client.get_recent_blockhash()9recent_blockhash = json_request["result"]["value"]["blockhash"]10txn = Transaction(fee_payer=sender.public_key(), recent_blockhash=recent_blockhash)11txn.add(12transfer(13TransferParams(14from_pubkey=sender.public_key(),15to_pubkey=reciever.public_key(),16lamports=100017)18)19)20txn.sign(sender)21print(solana_client.send_transaction(txn, sender))
1使用 reqwest::標頭;2使用 reqwest::客戶端;3use std::error::Error;45#[tokio::main]6async fn main() -> Result<(), Box<dyn Error>> {7let mut headers = header::HeaderMap::new();8headers.insert("Content-Type", "application/json".parse().unwrap());910let client = Client::new();11let json_data = r#"12{13"method": "sendTransaction",14"params": [15"ENTER_ENCODED_TRANSACTION_ID"16],17"id": 1,18"jsonrpc": "2.0"19}20"#;21let 回應 = client22.貼文(「https://docs-demo.solana-mainnet.quiknode.pro/」)23.標頭(標頭))24.正文(json_data)25.發送()26.await?;2728let body = response.text().await?;29println!("{}", body);3031好(())32}
1使用 reqwest::標頭;2使用 reqwest::客戶端;3use std::error::Error;45#[tokio::main]6async fn main() -> Result<(), Box<dyn Error>> {7let mut headers = header::HeaderMap::new();8headers.insert("Content-Type", "application/json".parse().unwrap());910let client = Client::new();11let json_data = r#"12{13"method": "sendTransaction",14"params": [15"ENTER_ENCODED_TRANSACTION_ID"16],17"id": 1,18"jsonrpc": "2.0"19}20"#;21let 回應 = client22.貼文(「https://docs-demo.solana-mainnet.quiknode.pro/」)23.標頭(標頭))24.正文(json_data)25.發送()26.await?;2728let body = response.text().await?;29println!("{}", body);3031好(())32}
回應
1{2"jsonrpc": "2.0",3"result": "2id3YC2jK9G5Wo2phDx4gJVAew8DcY5NAojnVuao8rkxwPYPe8cSwE5GzhEgJA2y8fVjDEo6iR6ykBvDxrTQrtpb",4"id": 15}
1{2"jsonrpc": "2.0",3"result": "2id3YC2jK9G5Wo2phDx4gJVAew8DcY5NAojnVuao8rkxwPYPe8cSwE5GzhEgJA2y8fVjDEo6iR6ykBvDxrTQrtpb",4"id": 15}