Revert-Opcode

Solidity/Remix 錯誤:如果您發送值,則應支付建構子?

  • August 26, 2018

簡單的合約,但不要轉移 ETH!

pragma solidity ^0.4.24;

contract Upper {
   uint public count;

   constructor() payable public {}

   function() payable public {
       count++;
   }
}

contract Caller {
   function run(address addr) payable public {
       addr.transfer(msg.value);
   }
}

run在呼叫者合約中呼叫 -function 。然後run呼叫fallback函式返回錯誤Solidity/Remix Error : The constructor should be payable if you send value

但是,如果我在上層合約中呼叫 fallback-runction - tx - 成功!

你快沒油了。該transfer函式僅向其呼叫的地址提供 2300 gas。Upper寫入儲存的回退功能,消耗2300多gas。

您可以require(addr.call.value(msg.value)());改用,但通常最好將耗氣操作完全移出備用功能。

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