78 votes
Accepted

Is there a limit for transaction size?

Wow this is such an interesting question! TL;DR: the transaction size limit, at the time of writing, is about 780kB (about 3 million gas). But read on. There is no direct or fixed limit, neither for ...
q9f's user avatar
  • 32.8k
31 votes
Accepted

how to estimate gas cost?

Using Truffle and testrpc. It's actually pretty easy to build a development environment and test different use cases. For the gas estimation, it's mostly based on Web3 native functions: You can ...
Greg Jeanmart's user avatar
25 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,114
21 votes
Accepted

Are gas limit in transaction and block gas limit different?

Yes. Each transaction has a gas limit. For example, there could be 5 unmined transactions where each has a gas limit of 10, 20, 30, 40, 50. The block gas limit determines how many transactions can ...
eth's user avatar
  • 85.1k
19 votes
Accepted

Can a contract's internal storage keep increasing forever?

Yes, a contract has infinite internal storage. But there are 2 limits to practicality: gas costs and the block gas limit. Gas costs are discussed in: Is there anything stopping me from using the ...
eth's user avatar
  • 85.1k
18 votes
Accepted

Why was Frontier's "default" gasLimit = 3141592?

This is referred to as a "Nothing up my sleeve number" which is common practice for security / cryptography based software. From Wikipedia: In cryptography, nothing up my sleeve numbers are any ...
HodlDwon's user avatar
  • 927
17 votes

Is there a limit for transaction size?

As of 12/08/2017, the gas limit as detailed on EthStats.net is 6,700,314. The gas limit was 'stuck' at 4.7 million. It was recommended that miners change their settings such that the gas limit could ...
Thomas Clowes's user avatar
17 votes

Execution of Fallback function with more 2300 gas

I was confused by this questions and self answer, so I will try to clarify. The OP sent 1,000,000 gas to a smart contract from an external account. He/she incorrectly read the Solidity documentation ...
Thomas Jay Rush's user avatar
14 votes
Accepted

How growing contract storage increases the gas spending?

Stored data is stored entirely in the state. None of the storage needs to be loaded into VM memory in order to execute transactions on the contract, other than those entries that your contract ...
Nick Johnson's user avatar
  • 8,114
14 votes

Does Gas Limit have any bearing on transaction/mining time?

Yes, a transaction's gas limit can have an effect on the time it takes to get mined into a block. Larger gas limits can be more enticing to miners since their potential fee is gas limit * gas price. ...
eth's user avatar
  • 85.1k
14 votes
Accepted

How do you calculate gas limit for transaction with data in Ethereum?

According to Ethereum Yellow Paper, in order to calculate gas limit for transaction with non-zero data you will need to use the following formula: gasLimit = Gtransaction + Gtxdatanonzero × ...
Slava Fomin II's user avatar
13 votes

If view or pure function doesn't cost any gas, would they be abused/free ride?

pure and view functions only are "free" when you call them externally, as in you call that function by itself and run the calculation on your node. So if you had a function that returned "1+1", yes ...
Shawn Tabrizi's user avatar
12 votes
Accepted

How do I get `gasLimit` in web3?

Asking for the last block mined, it will return the gasLimit of the block https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethgetblock var block = web3.eth.getBlock("latest"); ...
denisgranha's user avatar
12 votes
Accepted

Error: "The contract code couldn't be stored, please check your gas limit"

How did you get the bytecode? Does it have the '0x' at the beginning? Can you try adding the '0x' when submitting the transaction? .deploy({ data: '0x' + bytecode, arguments: ['Hi there!'] }) If ...
Ismael's user avatar
  • 31k
12 votes
Accepted

If view or pure function doesn't cost any gas, would they be abused/free ride?

Just to add to @Shawn's good answer. Yes, you can abuse them. But as the pure and view computations are performed only on your own node you would only hurt your own node. You would not hurt the ...
Lauri Peltonen's user avatar
11 votes
Accepted

How to increase gas limit in block using geth?

While it's advised to not alter a chain's gas limit once created, it may become necessary to fiddle with the gas limit of an existing private blockchain, especially during development. On geth, this ...
Daniel Okwufulueze's user avatar
11 votes

how to estimate gas cost?

The answer provided by Greg Jeanmart perfectly explained how to estimate the gas cost for a function. Here I want to point out that the design of your function giveAwayDividend() might be vulnerable ...
longcc's user avatar
  • 146
11 votes
Accepted

Gas consumption of a view public function

You don't pay gas when calling a view function. This doesn't change the fact it still has operations to do, which have costs, and thus are subject to the upper-bound gas limit on the block, as well as ...
Elisha Drion's user avatar
  • 2,621
9 votes
Accepted

Solidity Exceeds block gas limit during Mocha Tests with Ganache-cli

The error message "n: Exceeds block gas limit" means your transaction has declared a gas value greater that the maximum allowed in the network. A client will reject such transaction. With ganache-...
Ismael's user avatar
  • 31k
9 votes
Accepted

Does using a very high gas limit somehow get your transactions executed slower?

In short: It's exactly as you suspect, a higher gas limit means your transaction is less likely to be included by miners. The reasoning: miners seek to maximize their profit within each block. Calls ...
iamdefinitelyahuman's user avatar
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.1k
8 votes
Accepted

How Geth and Parity knows the global gas limit?

The block gasLimit is in each block. Example: eth.getBlock(1500000) { difficulty: 34982465665323, extraData: "0xd783010305844765746887676f312e352e31856c696e7578", gasLimit: 4712388, ... }
eth's user avatar
  • 85.1k
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
  • 15.9k
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

How to increase gas limit in block using geth?

Short answer Can't or shouldn't. Better answer The block gaslimit is a property of the network. If you're using a private chain you can fiddle with it in the genesis block. On a real blockchain, ...
Rob Hitchens's user avatar
  • 54.8k
7 votes

Gas limit of a contract method call

When an externally owned account (EOA) signs a transaction, their client will usually estimate the gas requirement and provide enough to make it work. This doesn't always work out as expected. ...
Rob Hitchens's user avatar
  • 54.8k
7 votes
Accepted

Is there a gas limit for view requests?

If you are calling this from an external account (using web3 or similar) then there is no gas cost associated because the function is view and is resolved in the node you are connected to. On the ...
Jaime's user avatar
  • 8,280
6 votes
Accepted

Private chain: Maximum size of "data" field in an Ethereum transaction?

In genesis.json you can set the block gas limit and then see How can I stop the block gas limit on a private chain dropping to the public chain default? Does it mean that I can transfer any amount ...
eth's user avatar
  • 85.1k
6 votes

Why was Frontier's "default" gasLimit = 3141592?

In addition to the answer explaining nothing up my sleeve number of pi million, it's worth to add that the gas limit is not set in stone. As the yellow paper equations describe the gas limit can ...
q9f's user avatar
  • 32.8k
6 votes
Accepted

For higher priority would it be a good idea to send a transaction with highest gasPrice?

Don't confuse gas value with gasprice. web3.eth.sendTransaction({/* ... */,gas: 99570000 , gasPrice: 12345}); Miners will Prioritize the transactions with a higher gas price not a gas value (how ...
Badr Bellaj's user avatar
  • 18.7k

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