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 or API are only available on supported networks. Check out the list of supported networks.
example
tenderly_simulateTransaction method. See RPC reference.
Example
- request
- response.json
request
Simulate via API
Use the simulate API endpoint to simulate a single transaction with different parameters.To use Simulations on Virtual Environments, we recommend the Simulate RPC and Bundle Simulate RPC.
Otherwise, you may use Virtual Environments Simulation API.
Simulation API endpoint on public network
Simulation API endpoint on a Virtual Environment
Request payload
Send aPOST request to the API endpoint. For full details on the request payload, see the 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.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.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.
Block number and transaction index
block_number and transaction_index select the state the transaction executes on. Both are optional integers.
Validation rules:
block_numberis an integer. Block tags such as"latest"or"pending"are rejected with a 400Bad request input parameterserror.transaction_indexrequires an explicitblock_number. With the block omitted, a non-zero index is rejected with 400Transaction index is not allowed when block number is pending.- An index greater than the block’s transaction count fails with
transaction index too high: invalid transaction simulation. The index is not clamped, and there is no keyword for the end of the block.
post-state of the latest block
0, At tx is the chosen index, and At end of block is the block’s transaction count.
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
- response.json
request.ts
Explore use cases
- Preview transaction outcomes: Identify and fix issues that could cause transactions to fail.
- Asset and balance changes: Get exact dollar values for all balance and asset changes that will happen.
- Gas estimation: Accurately predict the gas costs before sending the transaction.
- State overrides: Modify blockchain conditions like timestamps and contract data to test different scenarios.