7

Trying to call sendFundsToFriend() method on the testnet contract https://testnet.etherscan.io/address/0xce8efd03766a309af57ddeb9c79f3e7cd23da0df (contract code at https://gist.github.com/anonymous/5bdc3d9032a8b3cb5cba7c7625afa4d7 ) I got:

Warning! Error encountered during contract execution [Out of gas]

The tx result says:

Result: {
  "blockHash": "0x585ca866c5143090c7a82443269d55658a176a018b1ad90827ec70adc1ff66c8",
  "blockNumber": 465927,
  "contractAddress": null,
  "cumulativeGasUsed": 508930,
  "from": "0xe5f68950d479fab12797dabbe5a4b0d88ec7a722",
  "gasUsed": 58787,
  "logs": [],
  "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  "root": "0x1289d7517d81fa8c4894c0cd97fd200ec4e9f0fecebba586435daca8e4e8f9ec",
  "to": "0xce8efd03766a309af57ddeb9c79f3e7cd23da0df",
  "transactionHash": "0x703d7657c093557d1cd42dfeb7b8d0d3b74e413d22e8009b26d7ac966c85d048",
  "transactionIndex": 3
}
Transaction cost: 58787 gas.

enter image description here

When sending the tx, Transaction gas limit is set to 3000000, the default browser-solidity value.

If tx cost is 58787 gas and the limit is 3000000, why the out of gas error? Any idea? Thx!

P.S.: Tried a similar tx from a geth node instead of using metamask+browser-solidity and it worked ok:

https://testnet.etherscan.io/tx/0x56465b6594769578d9223ca902757780600dd2628074aedcf9635fb590b75bfa

So, I am doing something wrong with browser-solidity when calling the contract method, or might be some kind of bug in this environment...

7
  • 1
    It's cumulateGasUsed you need to check, 508930 Commented Feb 3, 2017 at 16:15
  • According to ethereum.stackexchange.com/questions/3346/… the Cumulative Gas has to do with all txs in the same block. Why should I pay fees for all txs in the block? Commented Feb 3, 2017 at 17:02
  • 1
    Besides, 3000000 is higher than 508930 Commented Feb 3, 2017 at 17:59
  • 1
    @JuanIgnacioPérezSacristán: Sorry you were right, cumulative is all transactions Commented Feb 4, 2017 at 11:26
  • 1
    It's hard to help you if we can't see the contract code. Could you post the relevant solidity? Commented Feb 4, 2017 at 19:30

3 Answers 3

4
+50

My theory, looking at the transactions of the deployed, is that the failed transactions were to a non-existent address (zero nonce, zero ETH before), and the successful ones were to an existent address (apparently had transactions in the past and ETH already). The former would consume more gas, pushing it beyond the normal gas limit.

The way to test this would be to use metamask+browser-solidity to send to an address that already had ETH. If it fails, then it's not the case. If it doesn't fail, then this is probably what happened.

It may still be a bug in metamask, as it miscalculated how much gas to provide.

EDIT:

I may have found the answer.

Compare a successful geth with an unsuccessful metamask (I presume) shows that the raw transactions are actually different. I suspect whichever client sent the unsuccessful transaction is formatting fields differently, or just buggily.

At this point I'd file a bug with metamask. It's beyond my own ability to debug.

6
4

At first I thought maybe we were mis-calculating gas somehow and failing transactions, since most of the failed txs have very low gas, but actually sometimes nearly identical transactions seemed to succeed with lower gas, like this pair: https://testnet.etherscan.io/tx/0x5dde4e0536756b380b34a6fed79bda50bbe274c25b07ac1812f0d816917b9fbd https://testnet.etherscan.io/tx/0xd2f0047ee8d6ed27a8435352c809a95484e9c3c0d63a2f672a32dd9a4243e90c

One thing I notice, is that these two are actually different contracts, so I'm not sure which one you posted the source code of.

It's also worth noting that you're using a few patterns for sending that are not recommended in the Solidity docs: https://solidity.readthedocs.io/en/develop/security-considerations.html?highlight=send#sending-and-receiving-ether

I do notice that some of the failed transactions are to contracts, and those are some of the more dangerous times to use the send function, since those contracts could burn up the gas.

Sorry, spent a while on this, not sure I found it.

3
  • My fault. There are two versions of the contract, but the latest is this one testnet.etherscan.io/address/… and it is this one that corresponds to the source code. Commented Feb 7, 2017 at 10:01
  • So, should I use a withdraw pattern instead of a send pattern? Commented Feb 7, 2017 at 10:06
  • 1
    You should probably use withdraw instead of send, but this doesn't quite answer why this happened.
    – DanF
    Commented Feb 8, 2017 at 6:04
1

I was facing same issue with Remix + Ganache, I switched to other Ethereum Test Net and issue didnt poped up. Try with some other test-net.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.