How to Simulate Transactions with Tenderly SDK
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
- Node.js installed on your machine
- Tenderly account with an API key
- Project set up in the Tenderly Dashboard
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 namedindex.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
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 toindex.js:
example.js
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.
Step 5: Run the transaction simulation
Now, use the Tenderly SDK’ssimulateTransaction method to run the transaction simulation.
Add the following code to index.js:
example.js
simulateTransaction method and logs the simulation result to the console.
Step 6: Execute the script
Save theindex.js file and run the script using the following command:
example