The Stack Overflow podcast is back! Listen to an interview with our new CEO.
58

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 transaction sizes nor for block sizes. This is a strength of the Etherem network, it does scale. That does not mean that there are no limits. There is the block ...


24

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 separate count of live elements: uint numElements = 0; uint[] array; function insert(uint value) { if(numElements == array.length) { array.length += ...


21

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 retrieve the gas price (in wei) using web3.eth.getGasPrice The function estimateGas will give the gas estimation for a function (with the parameters passed) ...


17

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 fit in a block. For example, if the block gas limit is 100, then the first four transactions can fit in the block. Miners decide which transactions to include ...


17

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 ethereum blockchain as data storage? Furthermore, the block gas limit will limit how much computation, search, iteration, etc can be performed on the data.


17

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 numbers which, by their construction, are above suspicion of hidden properties. They are used in creating cryptographic functions such as hashes and ciphers. ...


15

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 to say that there was a 'stipend' of only 2300 gas on such a transaction, but that was mistaken. The 'stipend' applies to internal sends from one smart ...


14

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. However, this is a potential fee, since unused gas is refunded. Thus, it is possible that transactions with very high gas limits, can be prioritized lower by ...


13

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 be raised. As outlined in this article, this happened. Each hexadecimal character is 4 bits. 2 characters is a byte. The yellow paper outlines the fees for ...


13

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 explicitly loads in code. As a result, gas costs are independent of the amount of stored data you have (unless you're doing something like iterating over every stored ...


12

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 you can call that individual view function as many times as you want for free, even without creating a transaction. However, if you use a view or pure function ...


11

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 Ethereum network in any way. If you call the function(s) enough, you might even crash your node but it still wouldn't hurt the network in any way.


8

The block gasLimit is in each block. Example: eth.getBlock(1500000) { difficulty: 34982465665323, extraData: "0xd783010305844765746887676f312e352e31856c696e7578", gasLimit: 4712388, ... }


8

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"); console.log("gasLimit: " + block.gasLimit);


8

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 can be done by setting the --targetgaslimit flag when starting the node. For example, you may do the following for a network with id 666 running on localhost:...


8

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 to attack. Since each of the for loop is paying ether to a user, and it only executes the next loop after this payment is successfully sent, it could be the ...


7

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 transaction will not be sent to miners. Other clients probably have a similar error. If my gas cost is 4,141,592 for example can 3,141,592 be paid in one block ...


7

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 × dataByteLength where: Gtransaction = 21000 gas Gtxdatanonzero = 68 gas dataByteLength — your data size in bytes So, the final formula would look like ...


7

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 you put '0x' in front of the bytecode it will assume the rest is in hexadecimal and left it alone. If there's no '0x' it will convert the whole string to ...


6

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 of data between accounts and all of this gets stored in the private blockchain forever? Yes.


6

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 much gas are you providing to be used to execute your transaction). the miners set a gasprice(the gas price you are willing to pay in ether for each unit of gas) ...


6

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 refund is issued later in the contract, it will bring the cumulative gas down even though it rises above what you think is the "gas limit" during the execution of ...


6

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 provided by even a single unit, you'll lose all the provided gas and the transaction will be rolled back.


5

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 refunds are only provided at the end of the transaction: one must provide enough gas during the entire transaction, otherwise an Out of Gas exception will cause ...


5

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 running out of gas: > eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], gas:21000, value: web3.toWei(10, "ether")}) "...


5

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 adjust with every block plusminus 1/1024 which is around 0.09%. In case of a very high network utilization, the network could adjust the gas limit by a factor of ...


5

Please paste the command you are trying to send the transaction with. A plain transaction needs 21000 gas per the protocol parameters. A block on the current main net goes up to 3 * PI million / 2, or somewhat above 4 million gas. If you get an error that the transaction exceeds the block gas limit, it usually means that you actually requested an enormous ...


5

Since you are doing this on a test network, you can modify your genesis block to have a gas limit of 0x2fefd8 which is the same as the main network (3,141,592 gas). You will also need to reset that test chain since you'll be changing the genesis block.


5

From Library contract method failing #2831: You probably run geth with the --dev option to create a private network? In that case use the init subcommand to create a private chain. Instructions can be found in the wiki. Or use the testnet. The problem is that this code uses the delegatecall which is added in the homestead release. The --dev flag uses ...


5

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 Genesis block. TargetGasLimit = new(big.Int).Set(GenesisGasLimit) // The artificial target Miners can increase or decrease the block gas limit by a factor of ...


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