Solidity

Solidity 0.6及以上版本如何充值到WETH?

  • November 23, 2020

Solidity 0.6.0ETH 轉賬的執行方式進行了重大更改。以下不再起作用:

weth.deposit.value(amount)();

將 ETH 存入WETH合約的最新語法是什麼?

堅固度 0.6 和 0.7

這是一個簡單的實現,您可以在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 }();
 }
}

引用自:https://ethereum.stackexchange.com/questions/90449