AptosAptos Network's breakthrough technology and seamless user experience are now available on QuickNode.

Start building today!     

Contents

simulateTransaction RPC Method

The API credit value for this method is 1 . To learn more about API credits and each method's value, visit the API Credits page.

Parameters:

  1. transaction - string - The transaction as an encoded string. The transaction must have a valid blockhash, but is not required to be signed
  2. object - (optional) The configuration object with the following fields:

    Commitment - string - (optional) (default: finalized) The level of commitment required for the query. The options include:

    Finalized - string - The node will query the most recent block confirmed by the supermajority of the cluster as having reached maximum lockout, meaning the cluster has recognized this block as finalized

    Confirmed - string - The node will query the most recent block that has been voted on by the supermajority of the cluster

    Processed - string - The node will query its most recent block. Note that the block may not be complete

    sigVerify - boolean - (default: false) If true, the transaction signatures will be verified (conflicts with replaceRecentBlockhash)

    replaceRecentBlockhash - boolean - (optional) (default: false) If true, the transaction recent blockhash will be replaced with the most recent blockhash (conflicts with sigVerify)

    encoding - string - (optional) (default: base58) The encoding format for account data. It can be either base58 (slow, DEPRECATED) or base64

    minContextSlot - integer - (optional) The minimum slot at which the request can be evaluated

    accounts - object - (optional) The accounts configuration object containing the following fields:

    addresses - string - (optional) An array of accounts to return, as base-58 encoded strings

    encoding - string - (optional) The encoding format for account data. It can be one of base58 (slow), base64, base64+zstd or jsonParsed

Returns:

  1. result - Null if the account doesn't exist otherwise RpcResponse JSON object with the following fields:

    context - An object that contains metadata about the current state of the Solana network at the time the request was processed

    apiVersion - The version number

    slot - The current slot in the Solana cluster during which the transactions are processed and new blocks are added to the blockchain

    err - Error code if the transaction failed or null if the transaction succeeds

    logs - An array of log messages the transaction instructions output during execution, null if simulation failed before the transaction was able to execute (for example due to an invalid blockhash or signature verification failure)

    accounts - An array of accounts with the same length as the accounts.addresses array in the request

    null - If the account doesn't exist or if err is not null

    object - otherwise, a JSON object containing:

    lamports - The number of lamports assigned to this account as u64 (64-bit unsigned integer)

    owner - The base-58 encoded Pubkey of the program this account has been assigned to

    data - The data associated with the account, either as encoded binary data or JSON format {'program': 'state'}, depending on encoding parameter

    executable - A boolean indicating if the account contains a program (and is strictly read-only)

    rentEpoch - The epoch at which this account will next owe rent, as u64 (64-bit unsigned integer)

Code Examples:

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("http://sample-endpoint-name.network.quiknode.pro/token-goes-here/")
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))
Ready to get started? Create a free account