Skip to main content
In this tutorial, you’ll learn how to run a transaction simulation using the Tenderly SDK. Simulations allow you to test the behavior of your transactions without sending them on-chain. Learn more about Tenderly’s Transaction Simulator here.

Prerequisites

Use this link to sign up for Tenderly.

Step 1: Initialize a new Node.js project

Create a new directory for your project, navigate to it in the terminal, and initialize a new Node.js project:
example

Step 2: Install Tenderly SDK

Install the Tenderly SDK npm package as a dependency in your Node.js project:
example

Step 3: Import the Tenderly SDK and configure it

Create a new file named index.js in your project directory, and add the following code to import the Tenderly SDK and configure it with your Tenderly account details:
example.js
Make sure to replace your-account-name, your-project-name, and your-access-key with your actual Tenderly account information.
Follow these guides to obtain the configuration details.

Step 4: Define the transaction details

Next, define the transaction details for the simulation. Add the following code to index.js:
example.js
Replace the from, to, input, value, gas, and gas_price fields with your desired transaction details. The override field is optional and allows you to override the state of specific contracts in the simulation.
Make sure that the specified block number actually exists on the selected network.

Step 5: Run the transaction simulation

Now, use the Tenderly SDK’s simulateTransaction method to run the transaction simulation. Add the following code to index.js:
example.js
This code runs an asynchronous function that calls the simulateTransaction method and logs the simulation result to the console.

Step 6: Execute the script

Save the index.js file and run the script using the following command:
example
If the transaction simulation is successful, you’ll see the simulation result printed in the console. That’s it! You’ve now learned how to run a transaction simulation using the Tenderly SDK.