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
Name | Type | Description |
---|---|---|
transactions | object | Transactions list of max 3 transactions to simulate. |
blockIdentifier? | string | Optional block identifier to simulate the transaction in. |
transactions
object parameters
transactions
object parametersProperty | Type | Description |
---|---|---|
data? | string | The data associated with the transaction. |
from? | string | The address the transaction is sent from. |
gas? | string | The gas provided for the transaction execution, as a hex string. |
gasPrice? | string | The gas price to use as a hex string. |
to? | string | The address the transaction is directed to. |
value? | string | The value associated with the transaction as a hex string. |
Response
Property | Type | Description |
---|---|---|
Promise<SimulateExecutionResponse> | object | Returns the transaction simulation response. |
SimulateExecutionResponse
object parameters
SimulateExecutionResponse
object parametersProperty | Type | Description |
---|---|---|
calls | array of object | An array of traces generated during simulation that represent the execution of the transaction along with the decoded calls if available. |
logs | array of object | An array of logs emitted during simulation along with the decoded logs if available. |
calls
array property parameters
calls
array property parametersProperty | Type | Description |
---|---|---|
decoded? | string | A decoded version of the call. Provided on a best-effort basis. |
error | string | Optional error field. |
gas | string | Gas provided for call as a hex string. |
gasUsed | string | Gas used during the call as a hex string. |
input | string | Call data. |
from | string | From address of the transaction. |
output | string | Return data. |
type | string | The type of call. |
value | string | Amount of value transfer as a hex string. |
to | string | To address of the transaction. |
logs
array property parameters
logs
array property parametersProperty | Type | Description |
---|---|---|
decoded? | string | A decoded version of the log. Provided on a best-effort basis. |
address | string | The address of the contract that generated the log. |
data | string | The data included the log. |
topics | array of strings | An 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.