🤔 Got questions? Schedule an office hours session.
Simulations
Single Simulations

Single Simulations

Tenderly supports single transaction simulations via RPC and API. Simulations are executed on the latest state of the chosen network.

Dapps and wallets can use single simulations to give their users a way to dry-run transactions before committing real assets. This gives them a preview of the transaction execution along with the detailed balance and asset changes that have occurred. Transaction previews can help users build trust in dapps, approve only successful transactions, and prevent costly failures.

Simulate via RPC

Node RPC allows you to read blockchain data and send transactions. But you can also simulate transactions on the Node. The advantage of simulating via RPC is that you can perform all these operations through a single RPC URL.

Simulations via RPC are only available on supported networks. If your network is not supported on the Node, use the Tenderly API instead. Check out the list of supported networks.

Retrieve your RPC URL and the access key from the Dashboard.

Go to Node > Copy HTTPS URL of the desired network.

example
https://mainnet.gateway.tenderly.co/$TENDERLY_NODE_ACCESS_KEY

To simulate a single transaction via RPC, call the tenderly_simulateTransaction method. See RPC reference.

Example

request
curl https://mainnet.gateway.tenderly.co/$TENDERLY_NODE_ACCESS_KEY \
  -X POST \
  -H "Content-Type: application/json" \
  -d \
  '{
    "id": 0,
    "jsonrpc": "2.0",
    "method": "tenderly_simulateTransaction",
    "params": [
      {
        "from": "0xe2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2",
        "to": "0x6b175474e89094c44da98b954eedeac495271d0f",
        "gas": "0x7a1200",
        "gasPrice": "0x0",
        "value": "0x0",
        "data": "0x095ea7b3000000000000000000000000f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1000000000000000000000000000000000000000000000000000000000000012b"
      },
      "0xfc497b"
    ]
  }'

Simulate via API

Use the simulate API endpoint to simulate a single transaction with different parameters.

To use Simulations on Virtual TestNets, we recommend the Simulate RPC and Bundle Simulate RPC.

Otherwise, you may use Virtual TestNets Simulation API.

The URL must contain your account slug and the project slug. Follow this quick guide to find the slugs.

Simulation API endpoint on public network
https://api.tenderly.co/api/v1/account/${TENDERLY_ACCOUNT_SLUG}/project/${TENDERLY_PROJECT_SLUG}/simulate
Simulation API endpoint on a Virtual TestNet
https://api.tenderly.co/api/v1/account/{accountSlug}/project/{projectSlug}/vnets/{vnetId}/transactions/simulate

You also need to receive the API access token, which is sent with the headers. Learn how to generate the API access key here.

Request payload

Send a POST request to the API endpoint. See API reference.

The simulated payload is similar to the eth_call JSON RPC call.

The fields below are required:

  • network_id (string): ID of the network where you want to run the simulation.
  • block_number (number): “latest” or the block number to be used for the simulation.
  • to (string): The recipient address of the transaction.
  • from (string): Address initiating the transaction.
  • input (string): Encoded contract method call data.
  • gas (number): Amount of gas provided for the simulation.

You can specify any sender address in the from field. Since Tenderly simulates unsigned transactions, you don’t need to own an account’s private key to simulate transactions from a specific sender.

You can also specify the simulation_type, which can be full, quick, or ABI. This field is not required since the default is set to full. Learn more about Simulation Modes.

When making API requests, add the X-Access-Key header with the value being the access token.

Example

Make sure to store the access key securely in a .env file.

request.ts
import axios from 'axios';
import * as dotenv from 'dotenv';
 
dotenv.config();
 
const simulateTransaction = async () => {
  const { TENDERLY_ACCOUNT_SLUG, TENDERLY_PROJECT_SLUG, TENDERLY_ACCESS_KEY } = process.env;
 
  const simulation = await axios.post(
    `https://api.tenderly.co/api/v1/account/${TENDERLY_ACCOUNT_SLUG}/project/${TENDERLY_PROJECT_SLUG}/simulate`,
    {
      network_id: '1',
      block_number: 16533883,
      from: '0xe2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2e2',
      to: '0x6b175474e89094c44da98b954eedeac495271d0f',
      gas: 8000000,
      gas_price: 0,
      value: 0,
      input: '0x095ea7b3000000000000000000000000f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1f1000000000000000000000000000000000000000000000000000000000000012b',
      simulation_type: 'quick',
    },
    {
      headers: {
        'X-Access-Key': TENDERLY_ACCESS_KEY as string,
      },
    },
  );
 
  console.log(simulation.data);
};
 
simulateTransaction();

Explore use cases

Where to go next