How to execute a swap
Last updated
Last updated
In this section, you'll learn how to request ready-to-use transaction data (bytecode) for executing a token swap.
As in the section, you can choose either the explicit path or the protocol-agnostic (less explicit) path to get the transaction data.
Use this when you want to work with a specific DEX protocol.
Request Transaction Data Fetch specific protocol information using:
Required Parameters:
action
Type of operation
swap
chainId
Blockchain network ID
137
(Polygon)
protocol
Protocol name
uniswap
fromToken
Token to swap from
ETH
toToken
Token to swap to
USDC
amountIn
Input amount
1000000000000000000
(1 ETH with decimals)
amountOut
Output amount
1820450000
(1820.45 USDC with decimals)
slippage
Maximum price slippage
0.5
(0.5% slippage tolerance)
deadline
Transaction deadline
1800
(30 minutes in seconds)
Example Request:
Response:
Our API returns the transaction data as an object containing to
, value
, and data
fields.
Let our system automatically select the optimal protocol for your needs.
Use the Generic Endpoint
Use the same parameters as above, excluding protocol
.
Example Request:
Response:
Execute the Transaction You'll need to sign and propagate the transaction data to the blockchain. This happens on your end - we don't touch your funds, custody remains yours.
After executing the swap, you can: