swaps:swap-to
Buy an exact amount of a token, spending as little as possible of another. The input is capped by --max, or --slippage applied to a quote (default 0.5%). Unspent input is refunded by the venue.
⚗️ Experimental — available at next.evmcrispr.com.
Supports runtime fields inside smart blocks. Use explicit @helper! expressions or captured outputs; other fields are evaluated at build time.
Syntax
Section titled “Syntax”swaps:swap-to <amountOut> <tokenOut> <from> <tokenIn>Arguments
Section titled “Arguments”| Name | Type | Evaluation | Description |
|---|---|---|---|
amountOut | number | Runtime in smart blocks | Exact amount of tokenOut to buy, in base units (wei) |
tokenOut | address | Build time | Token to buy |
from | command | Build time | Keyword from |
tokenIn | address | Build time | Token to spend (use @token(SYM); the native token resolves to the zero address) |
Options
Section titled “Options”| Name | Type | Evaluation | Description |
|---|---|---|---|
--fee | number | Build time | Explicit single-pool V3/V4 fee tier; required when a runtime amount cannot be quoted |
--max | number | Runtime in smart blocks | Maximum input in base units (overrides --slippage) |
--slippage | number | Build time | Maximum slippage vs. the quote, in percent (default 0.5) |
--using | swap-venue | Build time | Venue: Delora, UniswapV4, UniswapV3, UniswapV2, Honeyswap, SushiSwap, Balancer, or CoWSwap (default: the best venue available on the chain) |
--to | address | Runtime in smart blocks | Recipient of the output (defaults to the connected account) |
--deadline | number | Runtime in smart blocks | Unix timestamp after which the swap reverts (default: 20 minutes after the latest block) |
--no-approve | bool | Build time | Skip the automatic allowance check and approve action |
Examples
Section titled “Examples”# Buy exactly 1 GNO with WXDAI on Honeyswap (Gnosis), spending at most the quote plus 0.5%swaps:swap-to 1e18 0x9C58BAcC331c9aa871AFD802DB6379a98e80CEdb from 0xe91D153E0b41518A2Ce8Dd3D7944Fa863463a97d --using Honeyswap