1/5
## Solution: Balancer Swap rETH to WETH The solution for swapping rETH back to WETH using Balancer follows a similar pattern to when we swap from WETH to rETH. First, copy the code and paste it into the code editor. Then, change WETH to rETH, since we're pulling rETH into this contract from the message sender and then approving the Vault contract to spend it. ```solidity reth.transferFrom(msg.sender, address(this), wethAmountIn); reth.approve(address(vault), wethAmountIn); swap( WETH, RETH, wethAmountIn, rEthAmountOutMin, BALANCER_POOL_ID_RETH_WETH ); ``` Next, we're going to change the wethAmountIn to rEthAmountIn. ```solidity reth.transferFrom(msg.sender, address(this), rEthAmountIn); reth.approve(address(vault), rEthAmountIn); swap( WETH, RETH, wethAmountIn, rEthAmountOutMin, BALANCER_POOL_ID_RETH_WETH ); ``` That's it, we'll change the parameters around when we're calling the internal function swap. The token in will be rETH and token out will be WETH. The amount in will be rEthAmountIn and the minimum amount out will be wethAmountOutMin. The pool ID will be the same. ```solidity reth.transferFrom(msg.sender, address(this), rEthAmountIn); reth.approve(address(vault), rEthAmountIn); swap( RETH, WETH, rEthAmountIn, wethAmountOutMin, BALANCER_POOL_ID_RETH_WETH ); ``` Now let's run the test: ```bash forge test --fork-url $FORK_URL --match-path test/exercise-swap-balancer-v2.sol --match-test test_swapRethToWeth -vvv ``` The test passed, so let's take a look at the logs. For swapping one rETH to WETH, we get approximately 1.12 WETH.
A practical demonstration of swapping rETH to WETH using the Balancer Vault. The lesson covers how to use the Balancer Vault to exchange rETH to WETH, modifying the code from the previous lesson to accommodate the change in tokens being exchanged.
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