Portals Logo

Documentation
Guides
Get an Estimate

Get an Estimate

GET v2/portal/estimate

This endpoint is for estimating the expected quantity of tokens that will be received when executing a portal transaction. To take advantage of our simulation engine and to retrieve the most accurate estimates, it is recommended to provide the sender address in the request. This address must currently hold the inputAmount of the inputToken being sent.

The benefit of using this estimate endpoint is that token approvals are not needed, enabling you to see the expected (simulated) output before executing the transaction. This is especially useful for front-end applications that want to show the user the expected output before they execute the transaction.

NOTE: If you intended to execute the transaction payload from the portal endpoint in your own smart contract, you should use the sender address that currently holds the funds (e.g. your user's address) for this endpoint, and not the smart contract that will execute the payload.

If a sender address is not provided, this endpoint will not run a simulation and instead return the (approximate) equivalent amount of outputToken that would be received based on the current market conditions (i.e. USD prices). This mode may be useful if you need a quick conversion rate for a token pair.

Example

Estimating Output for Swapping Yearn yvWETH for yvCurve-stETH Tokens

Request

Estimate a swap of 10 Yearn yvWETH tokens for Yearn yvCurve-stETH tokens:

"inputToken":"ethereum:0xa258c4606ca8206d8aa700ce2143d7db854d168c",
"inputAmount":"10000000000000000000",
"outputToken":"ethereum:0xdcd90c7f6324cfa40d7169ef80b12031770b4325",
"sender":"0xbD4a00764217C13a246F86db58d74541A0C3972A"

NOTE: slippageTolerancePercentage is optional. If not provided, the default value is 2.5%

Response

The response includes the estimated output amount, the minimum output amount, the output token's address, decimals, as well as a context object with additional useful details about the estimate, like USD prices.

{
    "outputAmount": "8790073205714996804",
    "minOutputAmount": "8562538149486334405",
    "outputToken": "0xdcd90c7f6324cfa40d7169ef80b12031770b4325",
    "outputTokenDecimals": 18,
    "context": {
        "slippageTolerancePercentage": 2.5,
        "inputAmount": "10000000000000000000",
        "inputAmountUsd": 25552.228998941493,
        "inputToken": "ethereum:0xa258c4606ca8206d8aa700ce2143d7db854d168c",
        "outputToken": "ethereum:0xdcd90c7f6324cfa40d7169ef80b12031770b4325",
        "outputAmount": "8790073205714996804",
        "outputAmountUsd": 25575.455613739876,
        "minOutputAmountUsd": 24913.423273967957,
        "sender": "0xbD4a00764217C13a246F86db58d74541A0C3972A"
    }
}

The estimated output is 8.79 ($25,575 USD) of yvCurve-stETH tokens. The minOutputAmount is the minimum acceptable amount of tokens based on the slippageTolerancePercentage.