0/5
## Balancer WETH to rETH Swap Let's swap WETH to rETH using Balancer. The solution will be simple since there is already an internal function that will handle the swap between Balancer. So, all we have to do is make sure that we pass in the correct parameters: token in, token out, amount in, amount out min, and the pool ID that identifies the pool. This pool ID is also imported at the top of the file, and it is called `BALANCER_POOL_ID_RETH_WETH`. To swap WETH to rETH, we first need to pull in WETH, approve Balancer to spend this WETH, and then we will call the internal function swap. ```solidity weth.transferFrom(msg.sender, address(this), wethAmountIn); weth.approve(address(vault), wethAmountIn); swap( WETH, RETH, wethAmountIn, rEthAmountOutMin, BALANCER_POOL_ID_RETH_WETH ); ``` Next, we execute the test. Inside the terminal, this is the test command that we will execute. The file is called `exercise-swap-balancer-v2.sol` and the name of the function that we are going to execute is called `test_swapWethToReth`. ```bash forge test --fork-url $FORK_URL --match-path test/exercise-swap-balancer-v2.sol --match-test test_swapWethToReth -vvvv ``` The test has passed and this is the amount of rETH that you will get for putting in one ETH.
A comprehensive guide to swapping WETH to rETH using the Balancer Vault. This lesson covers the process of approving the Balancer Vault to spend WETH, then calling the `swap` function to execute the swap with the correct parameters.
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