0

trx fails at & debug at tenderly

pragma solidity 0.5.12;

contract WETH9_ 
{
mapping (address => uint)                       public  balanceOf;
mapping (address => mapping (address => uint))  public  allowance;

function() external payable ;
function deposit() external payable ;
function withdraw(uint wad) external ;
function totalSupply() external view returns (uint) ;

function approve(address guy, uint wad) external returns (bool) ;

function transfer(address dst, uint wad) external returns (bool) ;

function transferFrom(address src, address dst, uint wad) external returns (bool);
}


contract WrapUnwrap
{

WETH9_ internal WETH;
constructor (address payable WETHAddr) public {

    require(WETHAddr != address(0), "WETH is the zero address");

    WETH = WETH9_(WETHAddr);

}

    function wrap() payable public   
{
    uint256 ETHAmount =msg.value;

    //create WETH from ETH
    if (msg.value != 0) {
        WETH.deposit.value(msg.value)();
    }   
    require(WETH.balanceOf(address(this))>=ETHAmount,"Ethereum not deposited");
}


function unwrap(uint256 Amount) public 
{
    address payable sender= msg.sender;

    if (Amount != 0) {
        WETH.withdraw(Amount);
        sender.transfer(address(this).balance);
    }
}
}
  • This is a code-dump, not a question. Please fix it if you're expecting proper help here. – goodvibration Jun 2 at 6:39
  • modified the question – Akki Jun 2 at 6:59
1

This fails because there is no payable fallback. WETH.withdraw works by burning the supplied amount of the WETH tokens and transferring the same amount of ETH back to the sender. Since this contract can't receive ETH, the sending of ETH to it makes the transaction revert. Simply add the following to your contract so it can receive ETH:

   function() external payable {}
| improve this answer | |
  • really thanks for the answer – Akki Jun 3 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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