Skip to main content
46 votes
Accepted

How do I detect a failed transaction after the Byzantium fork as the REVERT opcode does not consume all gas?

Summary After the Byzantium fork, eth.getTransactionReceipt(...) will return a status field. The status field has a value of 0 when a transaction has failed with the REVERT opcode and 1 when the ...
BokkyPooBah's user avatar
  • 40.3k
29 votes

Truffle deployment on test network says: Error: exceeds block gas limit

Inside truffle.js, add ,gas: 4600000 Don't forget the little "," so it looks like networks: { development: { host: "localhost", port: 8545, network_id: "*", gas: ...
Russo's user avatar
  • 1,784
26 votes
Accepted

How to clear large arrays without blowing the gas limit?

The best way is simply not to clear them. In many (most?) situations, the array varies in size over time, and emptied slots will eventually be filled again. Instead of shortening the array, keep a ...
Nick Johnson's user avatar
  • 8,174
23 votes
Accepted

Why does a Solidity throw consume all gas?

All gas is consumed because the EVM essentially only has 1 exception: Out of Gas. To see this clearer, take a look at the difference between a "pure" exception, and an error due to bad/buggy/invalid ...
eth's user avatar
  • 85.9k
20 votes
Accepted

Does an entire transaction revert when throw occurs?

In Solidity, by default, yes. On the EVM-level, a throw (bad jump, out-of-gas, or any other exception) only reverts the call it is inside. Solidity helpfully continues the exception down the stack ...
Matthew Schmidt's user avatar
18 votes
Accepted

What happens if transaction runs out of gas before transaction completes?

Correct, it rolls back. Except for one thing: it gives the miner all the gas, you don't get that back. That's what keeps attackers from spamming, and it's fair anyway because the miner still had to do ...
Dennis Peterson's user avatar
17 votes
Accepted

Error: VM Exception while processing transaction: out of gas

First check your account balance : balance = web3.eth.getBalance(someAddress); then try to specify the gaslimit contractInstance.createProposal("ADHD", "Foo", 2, {from: web3.eth.accounts[1], gas:...
Badr Bellaj's user avatar
  • 18.8k
15 votes

Does an entire transaction revert when throw occurs?

To complement @Matthew's answer, it depends on how the call is made in Solidity. If C calls D.foo(), and foo does a throw, then yes the entire transaction is reverted. If C does a "lower-level raw ...
eth's user avatar
  • 85.9k
13 votes
Accepted

Who gets the fee from contract call?

"Call" is an overloaded term because it is one form of invoking a contract (see What is the difference between a transaction and a call?) and it depends where the invocation is performed, in relation ...
eth's user avatar
  • 85.9k
12 votes

How do I know when I've run out of gas programmatically?

Since block 4370000 (Byzantium) eth.getTransactionReceipt(transactionHash) will return a status field that has a value of 0 when a transaction has failed and 1 when the transaction has succeeded. ...
eth's user avatar
  • 85.9k
11 votes

Why does a Solidity throw consume all gas?

In part I believe this was a security decision to ensure spamming the network with bogus transactions cost the sender gas. For instance, if gas was refunded after a throw, a malicious actor could ...
Robert McCone's user avatar
10 votes

Out of Gas invoking precompiled contracts on private blockchains

There is a general gas cost rule that states that sending message to any non-existing account costs more than sending message to an existing account. That also applies to the accounts of the ...
Paweł Bylica's user avatar
9 votes
Accepted

All cases when Solidity compiles to invalid jump destination

Jumps to invalid jump destinations are generated only for (explicit or implicit) exceptions. An explicit exception is when you use the keyword throw. Implicit exceptions happen for runtime errors: ...
chriseth's user avatar
  • 3,412
8 votes
Accepted

How come I need to specify a higher gasLimit than estimateGas?

I believe in some cases cumulativeGasUsed is not accurate due to spending gas / refunding gas. If at any point the contract gets above the gasLimit, it will fail with an Out of Gas exception. If a ...
tayvano's user avatar
  • 16k
8 votes
Accepted

What happens when I send a transaction that exceeds the gas limit of 3,141,592?

The target block gas limit was PI million, but was increased to 1.5 PI million (4,712,388) in Homestead. If you exceed the limit, in Geth, you will get error "Exceeds block gas limit" and the ...
eth's user avatar
  • 85.9k
8 votes

My transaction failed due to running out of gas. Can I recoup this money?

That transaction had a very high gas price specified (0.000025 Ether, 25,000 GWei), while currently transactions are getting confirmed for much lower (0.000000002 Ether, 2 GWei). And the transaction ...
MidnightLightning's user avatar
7 votes

All cases when Solidity compiles to invalid jump destination

Array Out Of Bounds contract InvalidJump { uint[5] data; function invalidJump1() { uint i = 6000; data[i] = 1; } } And the message is from debug.traceTransaction(...) is: ...
BokkyPooBah's user avatar
  • 40.3k
7 votes
Accepted

Out of gas problem with transaction

An easier to interpret trace can be seen here at ether.camp. What happened is that the contract tried to call another contract, specifying a gas quantity of self.gas - 34050. Since your execution had ...
Nick Johnson's user avatar
  • 8,174
7 votes

How come I need to specify a higher gasLimit than estimateGas?

You don't. You can specify the gas exactly and it should go through just fine. The only gotcha is that if the contract state changes that you're executing against, and it would require more gas than ...
Péter Szilágyi's user avatar
7 votes

Why is my TX failing due to lack of gas even though the correct amount of gas was supplied?

Understanding this puzzle can be instructive. The behavior can be explained by the way the CALL instruction works in terms of gas. We can compare the transactions VM traces here: OK: https://live....
Yolanda Ruiz's user avatar
6 votes
Accepted

Specifying gas amount for contract call from JavaScript

Try changing contracts['CrowdFunder'].contract.contribute({ value: web3.toWei(0.000000000000000005, 'ether') }); to contracts['CrowdFunder'].contract.contribute({ value: web3.toWei(0....
BokkyPooBah's user avatar
  • 40.3k
6 votes
Accepted

Do nodes by default relay transactions that fail and spend all gas (e.g. Solidity throw)?

Yes, nodes relay the transactions by default. Transactions are relayed before they are executed and their gas consumption and behavior is determined. Nodes just do a basic check such as: is the ...
eth's user avatar
  • 85.9k
6 votes

Cannot tranfer() ETH to Gnosis Safe

This is explanied here: https://help.gnosis-safe.io/en/articles/5249851-why-can-t-i-transfer-eth-from-a-contract-into-a-safe You can also check further information in this post https://consensys....
Daniel Sánchez's user avatar
5 votes
Accepted

How to simulate out of gas events on a private blockchain?

Resend your transaction specifying a higher gas amount. If you omit the gas parameter from the eth.sendTransaction(...) call, a default of 21000 is used for plain vanilla transactions. To simulate ...
BokkyPooBah's user avatar
  • 40.3k
5 votes

How come I need to specify a higher gasLimit than estimateGas?

Here are general tips, followed by a synthesis of the other answers and comments to explain this particular situation. General tips estimateGas, as its name implies, is not always 100% accurate gas ...
eth's user avatar
  • 85.9k
5 votes
Accepted

Is it possible that the block gas limit will drop below its current level?

Here are the current values for Geth: MinGasLimit = big.NewInt(5000) // Minimum the gas limit may ever be. GenesisGasLimit = big.NewInt(4712388) // Gas limit of the ...
eth's user avatar
  • 85.9k
5 votes

Who gets the fee from contract call?

In the case that the transaction executes successfully, the actual fee goes to the miner that solves the block. To avoid redundancy, I'll just point to some details here: How do Ethereum's ...
Rob Hitchens's user avatar
  • 55.4k
5 votes
Accepted

Out of gas and atomicity

When a contract run into an error (bad jump, out-of-gas, or any other exception) it throw an error and the entire transaction is reverted. The reason for reverting is that there is no safe way to ...
0xCrema.eth's user avatar
  • 1,192
5 votes

If Metamask Gas calculations are nearly perfect why do we still get out of Gas error?

Gas estimation is not an exact science. There are certain cases when the gas estimate can be wrong, or impossible to estimate properly. Certain such cases depend on behaviour. If a contract has ...
Raghav Sood's user avatar
  • 4,060
5 votes

If Metamask Gas calculations are nearly perfect why do we still get out of Gas error?

Metamask's gas calculation is not perfect at all. The core of the problem lies in the eth_EstimateGas function that is simply running a contract and obtains usedGas value. This is how it does it in /...
Nulik's user avatar
  • 4,061

Only top scored, non community-wiki answers of a minimum length are eligible