1

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)));

enter image description here But I still get an error with the Withdraw function.. enter image description here 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)));
    }
}
2
  • Does your contract have a payable fallback or receive function? Without one of those, calls to WETH.withdraw will fail since it can't send the ETH back to the contract
    – natewelch_
    Commented Sep 11, 2022 at 18:28
  • Hello, yes it does have it. I even put a log inside the payable receive function in order to be sure it was sent to the function and it does show up in the tx events. @natewelch_ Commented Sep 11, 2022 at 18:37

1 Answer 1

1

Do you need to approve the amount you are unwrapping

2
  • No it is not needed when unwrapping Ether. I still have no idea why the code is not working sadly Commented Sep 18, 2022 at 12:23
  • unwrapping is just reducing the ERC20 balance and sending it to the contract so isnt it approving it for transfer? Commented Sep 18, 2022 at 19:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.