1/5
## Uniswap V3: Swap WETH to rETH Let's review the solution for swapping WETH into rETH using Uniswap V3. In this case, it's a fairly simple process since we're going to call an internal function that will handle the Uniswap V3 swap. All we have to do is pass in the correct parameters into the internal function. The parameters to pass are: tokenIn, tokenOut, fee, amountIn, amountOutMin, and the receiver. In this function, we'll call that internal function, swap. Before that though, we first need to pull the WETH into this contract from the message sender, and then approve the Uniswap V3 router, to pull the WETH from this contract. First, let’s pull the WETH from message sender: ```solidity weth.transferFrom(msg.sender, address(this), wethAmountIn); ``` Next, we'll approve the Uniswap V3 router to pull the WETH from this contract over to the router: ```solidity weth.approve(address(router), wethAmountIn); ``` Then, call the internal function swap, and pass the required parameters. The first input is tokenIn. TokenIn is WETH. TokenOut is rETH. The fee that identifies the pool is declared and imported from the constants: ```solidity UNISWAP_V3_POOL_FEE_RETH_WETH ``` Next is amountIn. ```solidity wethAmountIn ``` Next is minAmountOut: ```solidity rEthAmountOutMin ``` The last parameter is the receiver of rETH: ```solidity address(this) ``` The full swap function should look like: ```solidity swap(WETH, RETH, UNISWAP_V3_POOL_FEE_RETH_WETH, wethAmountIn, rEthAmountOutMin, address(this)); ``` To execute the test, we'll use the following command: ```bash forge test --fork-url $FORK_URL --match-path test/exercise-swap-uniswap-v3.sol --match-test test_swapWethToReth -vvv ``` The test passes, and for swapping one WETH to rETH, we get back approximately 0.891 rETH.
A comprehensive guide to swapping tokens using Uniswap V3 - The lesson shows how to swap WETH to rETH using Uniswap V3 and discusses the process of pulling the WETH tokens from message center and approving the Uniswap V3 router to access the WETH.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
Rocket Pool rETH staking, yield mechanisms, trading options, and contract architecture
How to distribute rewards and calculate rETH/ETH exchange rate
How to acquire and redeem rETH
Integrating rETH into DeFi protocols like AAVE V3
How to how to create leveraged ETH positions using rETH
How to provide rETH as liquidity to Balancer and Aura
Getting the USD price of rETH using Rocket Pool NAV oracle
Re-staking with EigenLayer
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)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Blockchain Financial Analyst
$100,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on May 12, 2025
Stay in the loop with the latest Rocket Pool updates and connect with over 5,000 developers in the community.
Solidity Developer
Rocket Pool rETH IntegrationDuration: 4min
Duration: 48min
Duration: 57min
Duration: 30min
Duration: 7min
Duration: 23min
Duration: 6min
Course Overview
About the course
Rocket Pool rETH staking, yield mechanisms, trading options, and contract architecture
How to distribute rewards and calculate rETH/ETH exchange rate
How to acquire and redeem rETH
Integrating rETH into DeFi protocols like AAVE V3
How to how to create leveraged ETH positions using rETH
How to provide rETH as liquidity to Balancer and Aura
Getting the USD price of rETH using Rocket Pool NAV oracle
Re-staking with EigenLayer
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)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Blockchain Financial Analyst
$100,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on May 12, 2025
Testimonials
Read what our students have to say about this course.
Chainlink
Chainlink
Gustavo Gonzalez
Solutions Engineer at OpenZeppelin
Francesco Andreoli
Lead Devrel at Metamask
Albert Hu
DeForm Founding Engineer
Radek
Senior Developer Advocate at Ceramic
Boidushya
WalletConnect
Idris
Developer Relations Engineer at Axelar