Skip to main content

How do I preview the output of a transaction?

Ask Enso Quoter to simulate the already-built transaction and read result.amountOut for each tokenOut you asked it to track, plus result.status and gas.

J
Written by Javier Diaz

Ask Enso Quoter to simulate the already-built transaction and read result.amountOut for each tokenOut you asked it to track. Also check result.status and result.gas before you show the preview to the user.

Definition

A preview is the predicted token output — in wei, at simulation time — if this calldata were executed against current state. It is not a Route path-finding quote, and it is not a guaranteed on-chain fill after state moves.

How it works

  • Pass tokenOut as the list of output token addresses you want tracked, and tokenIn plus amountIn for the inputs.

  • Simulate the transaction on the correct chainId.

  • When result.status is "Success", result.amountOut is an array of predicted outputs, one per tokenOut.

  • Show those amounts, with gas, on the review screen. If status is "Error", do not present the output as a quote.

  • Validate the unsigned transaction before signing, and include slippage protection in the calldata, because the amountOut can differ slightly when the transaction is later mined.

How Enso does this

POST https://quoter.api.enso.build/api/v1/simulate returns result.amountOut from a forked EVM execution. See Simulating Transactions and How It Works. If Enso should choose the path itself, use the Route API, which already returns amountOut and minAmountOut for the route it built.

FAQ

Why is amountOut an array?

You can track more than one tokenOut. The array is in the same order as the tokenOut addresses you sent.

Can I use this preview as a minimum on-chain floor?

Quoter predicts output; it does not add a minAmountOut to your calldata. Put slippage protection in the transaction you built.

Related articles

  • How do I estimate tokens received from a contract call?

  • How do I track token flows in a Quoter simulation?

  • How do I show a quote before the user signs?

  • What is the difference between Route amountOut and Quoter amountOut?

  • How do I simulate a DeFi transaction before sending it?

Sources

Did this answer your question?