I have very basic contract like this:

pragma solidity ^0.4.15;

contract Test {
    function() public payable {

    function pay(uint _amount) public returns (uint) {
        require(this.balance >= _amount);

Once started on Remix with JavascriptVM it works as expected - payable function receives ethers and pay pay it to any address. But when I connect Remix to the locally running testrpc or to Rinkeby network this contract fails on line with transfer call with error transact to Test.pay errored: VM Exception while processing transaction: out of gas.

I tried to replace transfer with send without any luck.

Of course I and trying to pay less then current contract balance (sent 10 ETH, trying to pay out 5 ETH).


It is damn strange, but almost same contract works:

contract Test {

    event Event(string _msg, address _address, uint _amount);

    function() public payable {

    function pay(uint _amount) public returns (uint256) {
        require(this.balance >= _amount);

        _pay(msg.sender, _amount);

    function _pay(address _to, uint _amount) private {
        Event("Outcome", _to, _amount);

BUT! If I remove mentions of Event - it stops works with the same error!

UPD2: It becomess stranger and stranger. If in contract that works I remove returns (uint256) it stop working too. I am totally confues - why return value affects contract work? Why separated logic works and merged into one function - no?

  • What is the gas limit that you set? Do you have a link to transaction on rinkeby? – medvedev1088 Feb 16 '18 at 21:15
  • Is msg.sender a contract? When sending ether to a contract using transfer the gas is limited to 2300 'gas stipend' as a security measure. To allow more gas you have to use the low level call, like this require(msg.sender.call.value(_amount).gas(_gas)()); – Ismael Feb 17 '18 at 4:20
  • @medvedev1088 default one for transfer from contract. – Alex G.P. Feb 17 '18 at 4:37
  • @Ismael no, msg.sender is user's address. – Alex G.P. Feb 17 '18 at 5:20
  • @AlexG.P. I mean the gaslimit that you set for the transaction – medvedev1088 Feb 17 '18 at 7:54

out of gas error sometimes means that there is not enough gas to complete the transaction.

While before the introduction of REVERT opcode out of gas error could appear in case of a throw as it consumed all gas, with REVERT this error is more reliable and you can assume with high probability that it's an actual out of gas and not some other exception.

Try increasing the gas limit for your transaction and see if it works.

| 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.