1/5
### Exercise 2: Swapping Tokens using Exact Input For the second exercise, we'll call the `exactInput` function on the swap router 02 contract. We’ll be swapping 1000 DAI for WETH, and then WETH for WBTC. This will be done in a single call to the swap router contract by calling the `exactInput` function. The final token, WBTC, that comes out of this swap should be sent to this contract. Let's review the interface for swap router 02. We'll need to call the `exactInput` function, and prepare a struct called `ExactInputParams` which will be the input for the function call. The struct contains the following fields: * `path` which will encode the path from DAI to WETH, then from WETH to WBTC * `recipient` which is set to the test contract. * `amountIn` which will be set to 1000 DAI * `amountOutMinimum` which will be set to one or zero Note that for this exercise, WBTC has 8 decimals.
A comprehensive guide to Uniswap v3 swaps using the SwapRouter02 contract. This lesson covers the `exactInput` function and how to prepare the `ExactInputParams` struct for swaps involving multiple tokens.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
Concentrated liquidity and derive its equations
Uniswap V3 math
How to calculate the spot price of tokens
Single and multi position swapping
Factory contract architecture
How to calculate liquidity requirements
Uniswap V3 fee algorithm
Flash loans
TWAP price oracle
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Blockchain Financial Analyst
$100,000 - $150,000 (avg. salary)
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on May 15, 2025
DeFi Developer
Uniswap V3Duration: 3min
Duration: 35min
Duration: 25min
Duration: 22min
Duration: 1h 43min
Duration: 11min
Duration: 1h 03min
Duration: 12min
Duration: 51min
Duration: 41min
Duration: 10min
Duration: 7min
Course Overview
About the course
Concentrated liquidity and derive its equations
Uniswap V3 math
How to calculate the spot price of tokens
Single and multi position swapping
Factory contract architecture
How to calculate liquidity requirements
Uniswap V3 fee algorithm
Flash loans
TWAP price oracle
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Blockchain Financial Analyst
$100,000 - $150,000 (avg. salary)
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on May 15, 2025