simulateTransaction RPC Method
Parameters
transaction
string
Loading...
object
object
Loading...
commitment
string
Loading...
sigVerify
boolean
Loading...
replaceRecentBlockhash
boolean
Loading...
encoding
string
Loading...
minContextSlot
integer
Loading...
innerInstructions
boolean
Loading...
accounts
object
Loading...
addresses
string
Loading...
encoding
string
Loading...
Returns
result
Loading...
context
Loading...
apiVersion
Loading...
slot
Loading...
err
Loading...
logs
Loading...
accounts
Loading...
null
Loading...
object
Loading...
lamports
Loading...
owner
Loading...
data
Loading...
executable
Loading...
rentEpoch
Loading...
unitsConsumed
Loading...
returnData
Loading...
programId
string
Loading...
data
Loading...
innerInstructions
Loading...
Request
curl https://docs-demo.solana-mainnet.quiknode.pro/ \ -X POST \ -H "Content-Type: application/json" \ --data '{"method":"simulateTransaction","params":["ENTER_ENCODED_TRANSACTION_ID"],"id":1,"jsonrpc":"2.0"}'
require "uri" require "json" require "net/http" url = URI("https://docs-demo.solana-mainnet.quiknode.pro/") https = Net::HTTP.new(url.host, url.port) https.use_ssl = true request = Net::HTTP::Post.new(url) request["Content-Type"] = "application/json" request.body = JSON.dump({ "method": "simulateTransaction", "params": [ "ENTER_ENCODED_TRANSACTION_ID" ], "id": 1, "jsonrpc": "2.0" }) response = https.request(request) puts response.read_body
import { createSolanaRpc, generateKeyPairSigner, lamports, pipe, createTransactionMessage, setTransactionMessageFeePayer, setTransactionMessageLifetimeUsingBlockhash, appendTransactionMessageInstruction, signTransactionMessageWithSigners, } from "@solana/kit"; import { getTransferSolInstruction } from "@solana-program/system"; const LAMPORTS_PER_SOL = BigInt(1_000_000_000); (async () => { try { const solanaRpc = createSolanaRpc("https://docs-demo.solana-mainnet.quiknode.pro/"); console.log("✅ - Connected to Solana mainnet"); const fromWallet = await generateKeyPairSigner(); const toWallet = await generateKeyPairSigner(); const { value: latestBlockhash } = await solanaRpc.getLatestBlockhash().send(); const transactionMessage = pipe( createTransactionMessage({ version: 0 }), tx => setTransactionMessageFeePayer(fromWallet.address, tx), tx => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx), tx => appendTransactionMessageInstruction( getTransferSolInstruction({ amount: lamports(LAMPORTS_PER_SOL / BigInt(100)), destination: toWallet.address, source: fromWallet, }), tx ) ); const signedTransaction = await signTransactionMessageWithSigners(transactionMessage); const simulateResult = await solanaRpc.simulateTransaction(signedTransaction).send(); console.log('Simulate Transaction Result:', simulateResult); } catch (error) { console.error('Error occurred:', error); } })();
const web3 = require("@solana/web3.js"); (async () => { const solana = new web3.Connection("https://docs-demo.solana-mainnet.quiknode.pro/"); // Replace with your public/secret keypair, wallet must have funds to pay transaction fees. const fromWallet = web3.Keypair.generate(); const toWallet = web3.Keypair.generate(); const transaction = new web3.Transaction().add( web3.SystemProgram.transfer({ fromPubkey: fromWallet.publicKey, toPubkey: toWallet.publicKey, lamports: web3.LAMPORTS_PER_SOL / 100, }) ); console.log(await solana.simulateTransaction(transaction, [fromWallet])); })();
from solana.rpc.api import Client from solana.account import Account from solana.system_program import TransferParams, transfer from solana.transaction import Transaction #Make sure to paste sender, reciever addresses and public key. solana_client = Client("https://docs-demo.solana-mainnet.quiknode.pro/") sender, reciever = Account(1), Account(2) json_request = solana_client.get_recent_blockhash() recent_blockhash = json_request["result"]["value"]["blockhash"] txn = Transaction(fee_payer=sender.public_key(), recent_blockhash=recent_blockhash) txn.add( transfer( TransferParams( from_pubkey=sender.public_key(), to_pubkey=reciever.public_key(), lamports=1000 ) ) ) txn.sign(sender) print(solana_client.simulate_transaction(txn))
use reqwest::header; use reqwest::Client; use std::error::Error; #[tokio::main] async fn main() -> Result<(), Box<dyn Error>> { let mut headers = header::HeaderMap::new(); headers.insert("Content-Type", "application/json".parse().unwrap()); let client = Client::new(); let json_data = r#" { "method": "simulateTransaction", "params": [ "ENTER_ENCODED_TRANSACTION_ID" ], "id": 1, "jsonrpc": "2.0" } "#; let response = client .post("https://docs-demo.solana-mainnet.quiknode.pro/") .headers(headers) .body(json_data) .send() .await?; let body = response.text().await?; println!("{}", body); Ok(()) }
Response
{ "jsonrpc": "2.0", "result": { "context": { "slot": 218 }, "value": { "err": null, "accounts": null, "logs": [ "Program 83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri invoke [1]", "Program 83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri consumed 2366 of 1400000 compute units", "Program return: 83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri KgAAAAAAAAA=", "Program 83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri success" ], "returnData": { "data": [ "Kg==", "base64" ], "programId": "83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri" }, "unitsConsumed": 2366 } }, "id": 1 }
Don't have an account yet?
Create your QuickNode endpoint in seconds and start building
Get started for free