Simulate Transactions

Fordefi's REST API for simulation lets you predict an estimated outcome once the transaction is executed on the chain, as well as accurately estimate the transaction fees.

Send your request for an estimated prediction to the /api/v1/transactions/predict endpoint.

The simulation status can be extracted from the simulation_status_result.simulation_status field in the response.

Transaction simulation is performed in any case as part of the transaction submission on the platform (manual or programmatic), however using this endpoint allows you to preview the transaction’s details before it is actually submitted on the platform.

Simulation data

Simulation reports expected outcomes with respect to the following data:

Effects

To view the estimated transaction effects, refer to expected_result.effects. The following are the possible effect types:

  • transfers: Shows all the token transfers on any of your vaults as part of this EVM transaction.
  • allowances (EVM only): Shows all the ERC-20 token approvals given in this contact call.
  • balance_changes: Shows the aggregated balance changes per token as part of this transaction.
  • bridge (EVM only): Valid only for bridge transactions with a select number of supported bridges.

Fee estimation

Under expected_result.gas_debit, all the gas-related details for this transaction are listed:

  • gas_used: The exact gas used by this transaction.
  • gas_price: The current gas price (medium level).
  • total_fee: Total fee, calculated according to: gas_used*gas_price.

Revert reason

In case the simulation predicts that this transaction will revert, all the details can be found at expected_result.reversion:

  • state: The revert state of the transaction. It can be not_reverted, but in case the transaction was reverted, this state will indicate the reason for the revert.
  • reason: Additional information for the revert reason.

Risks

The simulation result is also screened by the Fordefi risk engine. The result of this screening can be retrieved through the risks field in the response.

There are several risk types that we identify. They are returned in the type field; one of these is severity, based on our risk engine.

Policy matching

As part of simulating the transaction, Fordefi matches it against the policy to show if and which policy rules will apply to the transaction once it is submitted for signature. The matching policy rule details can be found under policy_match , and the required approvers under approval_request.

Skip simulation

By default, all transactions created on the Fordefi’s platform are simulated to predict the exact transaction effects. The simulation enables Fordefi to extract the transaction effects and match them against the policy rules.

For programmatic transactions that are time sensitive, you can pass a skip_prediction=True flag in the transaction request body that will cause the transaction creation flow to skip simulation, and the transaction to be sent faster to the blockchain.

When you use this feature, recall that without transaction simulation, Fordefi does not have the full information of the transaction details, so we can match it only partially against the policy rules.

Override simulation errors

In case there is an error in the simulation for any reason, for example, a node error, Fordefi has a fallback mechanism that allows you to enforce a policy for the transaction. The transaction reverts to the default policy rule to allow you to set approval or block the transaction.

To enable this mechanism, set fail_on_prediction_failure=false in Create Transaction REST calls.

Learn more about this feature.