0
pragma solidity ^0.5.0;

contract Contract1 {

  address payable owner;
  uint public value;

  constructor() public payable {
    owner = msg.sender;  
    value = msg.value;
  }

  function() external payable {

    value = msg.value;

  }


}


contract Contract2{

    Contract1 public c;

    function setContract(address payable _addr) public{

     c = Contract1(_addr);

    }

    function() external payable{



    }

    function sendEther() public payable{

        address(c).transfer(msg.value);

    }



}

Whenever I try to call the sendEther() I get the following error

transact to Contract2.sendEther errored: VM error: revert. revert The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information.

  • If I try sending using send(), it shows a warning but still no ether is being transfered – Hackeerrrr Feb 7 at 8:55
  • 1
    The fallback function uses more gas than the gas stipend of 2300. The recommended solution is to explicitly invoke a payable function instead. – Ismael Feb 7 at 16:02
  • I have considered that solution as well but I want to experiment on sending ethers to SCs which have a default fallback function. I am new to SC development and so I am trying to learn these things. Pardon if it is stupid or too trival – Hackeerrrr Feb 10 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.