2

Solidity 0.6.0 introduced a breaking change in how ETH transfers are performed. The following doesn't work anymore:

weth.deposit.value(amount)();

What is the latest syntax for depositing ETH into the WETH contract?

Paul Razvan Berg
  • 17,902
  • 6
  • 73
  • 143
  • weth.deposit{value: amount}(); as far as I remember. – goodvibration Nov 23 '20 at 16:59
  • And BTW, WETH is not a fundamental part of the Ethereum standard or infrastructure. It's an ERC20 contract implemented by a "privately held" company. So the question here is generally for any payable function on any contract (I mean, that's how the question should be formulated IMO). – goodvibration Nov 23 '20 at 17:01
  • @goodvibration It depends on your standards, but to me holding 5,411,942 ETH (approximately $316M at the time of writing this) makes WETH a rather important public good in the Ethereum ecosystem. – Paul Razvan Berg Nov 23 '20 at 17:08
  • I included WETH in the formulation because I wanted this q&a to be very specific. Humans like specific examples. There is already another thread about payable functions in general. – Paul Razvan Berg Nov 23 '20 at 17:09

1 Answers1

2

Solidity 0.6 and 0.7

Here's a simple implementation that can you try out in Remix:

pragma solidity >=0.6.0;

interface WethLike { function deposit() external payable;

function withdraw(uint256) external;

}

contract MyContract { WethLike weth;

constructor(WethLike weth_) { weth = weth_; }

function foo() external payable { weth.deposit{ value: msg.value }(); } }

Paul Razvan Berg
  • 17,902
  • 6
  • 73
  • 143
  • Hello. I have followed what you said, but the Weth is not transferred to user's wallet. – Yaya Sep 24 '22 at 17:44