0

I am developing a DApp on the Kovan Network on Remix and I am having trouble understanding the problem. I am tring to call the Wrapped Ether contract (WETH : https://kovan.etherscan.io/address/0xd0a1e359811322d97991e03f863a0c30c2cf029c) from my own contract (to automaticly wrap / unwrap the ether my users deposit).

When I'm calling the contract from Etherscan through Metamask, I can deposit and withdraw WETH without any problem.

However the problem arise when I try to 'deposit' (with my wrapETH function) then 'withdraw' WETH through my contract. I realised the problem when my Withdraw attempts were always reverted. I realised that the deposit transaction was always pending on Remix, although the transaction was mined on its etherscan page (for example : https://kovan.etherscan.io/tx/0xe815da928878318b9e8eff18eb8ae353ebc0e8db9cd8fb2b39ca2b55f13d06f9), and that I could see the Event and check my balance on the WETH page.. The transaction itself also didn't appear on the WETH page. Another strange thing on this pending transaction is the 'input data' which is unreadable comparing with other transactions.

Does someone know what is happening, and why there is a difference between calling the WETH contract from Etherscan (again, where the transaction is mined and recorded directly) and not from my contract?

Here's the functions I'm calling (with only the useful)

WETH9_ WETHContract = WETH9_(0xd0a1e359811322d97991e03f863a0c30c2cf029c);

function depositETH() public payable{ 

}

function wrapETH(uint256 _amount) public{
     WETHContract.deposit.value(_amount)();
}

function withdrawETH(uint256 _amount) public{
    WETHContract.withdraw(_amount);
}

Thank you

1 Answer 1

0

The transaction is working as expected.

Your contract's parity trace shows it calling the WETH contract. Your transaction also raises the Deposit event for the value of the transaction. If you go to the WETH contract's read contract page and query the balance of 0xf2a800fa540060384ed4d778db7cafdf477df2ec, you get back an appropriate WETH balance.

The only difference would be in who receives the WETH. When you use Metamask to call the WETH contract directly, the WETH will be sent to the externally owned account that initiated the transaction.

When you go through your contract, your WETH is credited to your contract instead, since as far as WETH is concerned, the msg.sender is your contract.

You should be maintaining an internal ledger within your contract of user balances. When you call the withdraw function, the ether will come to your contract, and you will need to forward it on to the user.

3
  • Yes that's what I'm doing in the full version. However even in this version, the withdraw function do not work when it is called, but for me my contract (0xf2a...) should as you say have the WETH needed and thus be able to withdraw ETH from the WETH contract. Here is the transaction failed from the withdrawETH function : kovan.etherscan.io/tx/… Aug 15, 2018 at 21:36
  • It is working, you just need a payable fallback function in your contract to accept the ether Aug 15, 2018 at 21:38
  • 1
    It was indeed the fallback function!! I never knew I needed it for this.. Thanks a lot for your help! Aug 15, 2018 at 21:43

Your Answer

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

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