I am writing a smart contract that needs to Unwrap/Withdraw WETH at some point but the transaction is always reverting.
When calling this function, everything works perfectly fine and the Log I put in the receive function even picks up the fact that I received the ETH.
WETH.withdraw(WETH.balanceOf(address(this)));
But I still get an error with the Withdraw function.. Does anyone have an idea of why this might be?
Thank you
Complete code:
pragma solidity ^0.8.0;
import "./weth.sol";
contract Unwrap {
fallback() external payable {}
receive() external payable {}
function unwrap() external payable {
IWETH weth = IWETH(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
weth.withdraw(weth.balanceOf(address(this)));
}
}