1/5
### Exercise 3: Calling the Exact Output Single Function For exercise 3, we want to call the `exactOutputSingle` function on the swap router contract. In this exercise, we want to call the `exactOutputSingle` function to swap a maximum of 1000 DAI to obtain exactly 0.1 WETH. The WETH that comes out from the swap should be sent to this test contract. The function that we will need to call is `exactOutputSingle`. Let's take a look at the interface for `exactOutputSingle`. ```javascript function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn); ``` `exactOutputSingle` will be this function. Then we'll need to prepare this parameter to pass to this function: ```javascript struct ExactOutputSingleParams { address tokenIn; address tokenOut; uint24 fee; address recipient; uint256 amountOut; uint256 amountInMaximum; uint160 sqrtPriceLimitX96; } ``` `tokenIn`, `tokenOut`, and `fee` will determine the pool to swap on. `recipient` will be this test contract. `amountOut` will be 0.1 WETH. `amountInMaximum` will be 1000 DAI. Here we are saying that we're willing to spend a maximum of 1000 DAI and we want exactly 0.1 WETH. For `sqrtPriceLimitX96`, we will keep it simple and set it to 0. So that is exercise 3. We will call the function `exactOutputSingle`.
A comprehensive guide to using the exactOutputSingle function to swap tokens on Uniswap V3. The lesson covers how to use the exactOutputSingle function to swap a maximum amount of DAI to receive a specific amount of WETH, and how to use the function to define the price limit of the trade.
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