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.
Parâmetros
transação
cadeia de caracteres
A carregar...
objeto
objeto
A carregar...
skipPreflight
booleano
A carregar...
preflightCommitment
cadeia de caracteres
A carregar...
encoding
cadeia de caracteres
A carregar...
maxRetries
usize
A carregar...
minContextSlot
número inteiro
A carregar...
Devoluções
resultado
A carregar...
Pedido
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"}'
1exigir "uri"2require "json"3require "net/http"45url = URI("https://docs-demo.solana-mainnet.quiknode.pro/")67https = Net::HTTP.novo(url.host, url.porta)8https.use_ssl = true910pedido = Líquido::HTTP::POST.novo(url)11pedido["Content-Type"] = "application/json"12pedido.corpo = JSON.dump({13"method": "sendTransaction",14"params": [15"ENTER_ENCODED_TRANSACTION_ID"16],17"id": 1,18"jsonrpc": "2.0"19})2021resposta = https.pedido(pedido)22insere a resposta.read_body23
1exigir "uri"2require "json"3require "net/http"45url = URI("https://docs-demo.solana-mainnet.quiknode.pro/")67https = Net::HTTP.novo(url.host, url.porta)8https.use_ssl = true910pedido = Líquido::HTTP::POST.novo(url)11pedido["Content-Type"] = "application/json"12pedido.corpo = JSON.dump({13"method": "sendTransaction",14"params": [15"ENTER_ENCODED_TRANSACTION_ID"16],17"id": 1,18"jsonrpc": "2.0"19})2021resposta = https.pedido(pedido)22insere a resposta.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))
1use reqwest::header;2use reqwest::Client;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 response = client22.post("https://docs-demo.solana-mainnet.quiknode.pro/")23.headers(headers)24.body(json_data)25.send()26.await?;2728let body = response.text().await?;29println!("{}", body);3031Ok(())32}
1use reqwest::header;2use reqwest::Client;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 response = client22.post("https://docs-demo.solana-mainnet.quiknode.pro/")23.headers(headers)24.body(json_data)25.send()26.await?;2728let body = response.text().await?;29println!("{}", body);3031Ok(())32}
Resposta
1{2"jsonrpc": "2.0",3"result": "2id3YC2jK9G5Wo2phDx4gJVAew8DcY5NAojnVuao8rkxwPYPe8cSwE5GzhEgJA2y8fVjDEo6iR6ykBvDxrTQrtpb",4"id": 15}
1{2"jsonrpc": "2.0",3"result": "2id3YC2jK9G5Wo2phDx4gJVAew8DcY5NAojnVuao8rkxwPYPe8cSwE5GzhEgJA2y8fVjDEo6iR6ykBvDxrTQrtpb",4"id": 15}
Ainda não tem uma conta?
Crie o seu ponto de extremidade Quicknode em segundos e comece a desenvolver
Comece gratuitamente