simulateExecutionBundle - SDK

Simulates a list of transactions in sequence and returns list of decoded traces and logs that occurred for each transaction during simulation. Note that this method does not run any transactions on the blockchain.

Don’t have an API key?

Start using this method in your app today.

Description

Simulates a list of transactions in sequence and returns a list of decoded traces and logs that occurred for each transaction during simulation.

Note that this method does not run any transactions on the blockchain.

Parameters

NameTypeDescription
transactionsobjectTransactions list of max 3 transactions to simulate.
blockIdentifier?stringOptional block identifier to simulate the transaction in.

transactions object parameters

PropertyTypeDescription
data?stringThe data associated with the transaction.
from?stringThe address the transaction is sent from.
gas?stringThe gas provided for the transaction execution, as a hex string.
gasPrice?stringThe gas price to use as a hex string.
to?stringThe address the transaction is directed to.
value?stringThe value associated with the transaction as a hex string.

Response

PropertyTypeDescription
Promise<SimulateExecutionResponse>objectReturns the transaction simulation response.

SimulateExecutionResponse object parameters

PropertyTypeDescription
callsarray of objectAn array of traces generated during simulation that represent the execution of the transaction along with the decoded calls if available.
logsarray of objectAn array of logs emitted during simulation along with the decoded logs if available.

calls array property parameters

PropertyTypeDescription
decoded?stringA decoded version of the call. Provided on a best-effort basis.
errorstringOptional error field.
gasstringGas provided for call as a hex string.
gasUsedstringGas used during the call as a hex string.
inputstringCall data.
fromstringFrom address of the transaction.
outputstringReturn data.
typestringThe type of call.
valuestringAmount of value transfer as a hex string.
tostringTo address of the transaction.

logs array property parameters

PropertyTypeDescription
decoded?stringA decoded version of the log. Provided on a best-effort basis.
addressstringThe address of the contract that generated the log.
datastringThe data included the log.
topicsarray of stringsAn array of topics in the log.

Example Request and Response

Prerequisite: You will need to install the Alchemy SDK before making requests with it.

The commands for installing it using npm or yarn are given below:

npm install alchemy-sdk@latest
yarn add alchemy-sdk@latest

Request

// Imports the Alchemy SDK
const { Alchemy, Network } = require("alchemy-sdk");

// Configures the Alchemy SDK
const config = {
    apiKey: "alchemy-replit", // Replace with your API key
    network: Network.ETH_MAINNET, // Replace with your network
};

// Creates an Alchemy object instance with the config to use for making requests
const alchemy = new Alchemy(config);

const main = async () => {
    // define the transaction hash
    const trnxs = [
      {
      transaction:
"0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b"}
    ];

    //Call the method to display the transaction simulation execution
    const response = await alchemy.transact.simulateExecutionBundle(trnxs)

    //Logging the response to the console
    console.log(response)
}

main();

Response

{
  calls: [
    {
      type: 'CALL',
      from: '0xa7d9ddbe1f17865597fbd27ec712455208b6b76d',
      to: '0xf02c1c8e6114b1dbe8937a39260b5b0a374432bb',
      value: '0xf3dbb76162000',
      gas: '0x6fb0',
      gasUsed: '0x53a0',
      input: '0x68656c6c6f21',
      output: '0x'
    }
  ],
  logs: []
}

Code Sandbox

You can test out the simulateExecutionBundle method using the code sandbox below:

Use Cases

Here are some potential use cases for the simulateExecutionBundle method:

  • Testing: You can use simulateExecutionBundle to test the logic of your smart contract without incurring the cost of actually executing the transactions on the blockchain.

  • Gas estimation: The method can also be used to estimate the amount of gas required to execute a series of transactions. This can be useful in determining the appropriate gas limit to set for a transaction to ensure it is processed efficiently.

  • Debugging: When you encounter errors while interacting with a smart contract, simulateExecutionBundle can help you debug the issue. By simulating the execution of the set of transactions, you can identify the specific line of code that is causing the error.

Related Methods

Here are the methods related to simulateExecutionBundle:

  • simulateExecution: Simulates a single transaction and the results and returns a list of decoded traces and logs that occurred during the transaction simulation.
ReadMe