Simple contract, but don't transfer ETH!

pragma solidity ^0.4.24;

contract Upper {
    uint public count;

    constructor() payable public {}

    function() payable public {

contract Caller {
    function run(address addr) payable public {

I call run-function in Caller contract. Then run call fallback function return error Solidity/Remix Error : The constructor should be payable if you send value

But if I call fallback-runction in Upper contract - tx - success!

  • 1
    How are you deploying the two contracts? Which function are you calling on which contract? With what parameters (if any)? If you're using code to deploy the contracts and call them, please share your code. – user19510 Aug 26 '18 at 9:05
  • @smarx open Remix, paste this code, deploy Upper contract, after deploy Caller contract. Run run-function, and tx return this error! – Nikolay Aug 26 '18 at 9:08
  • And I assume you're supplying exactly one parameter to run(), and the value of that parameter is the address of the deployed Upper contract. That's the sort of information people need so they can try to reproduce and diagnose your issue. – user19510 Aug 26 '18 at 9:12
  • I also assume the full error is "transact to Caller.run errored: VM error: revert. revert The transaction has been reverted to the initial state. Note: The constructor should be payable if you send value. Debug the transaction to get more information." That full error message is often also helpful. – user19510 Aug 26 '18 at 9:13

You're running out of gas. The transfer function only supplies 2300 gas to the address it calls. The fallback function of Upper writes to storage, which consumes more than 2300 gas.

You could use require(addr.call.value(msg.value)()); instead, but it's generally better to move gas-consuming operations out of the fallback function altogether.

| improve this answer | |

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.