Skip to main content
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
22 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
  • 86.2k
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
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
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
  • 86.2k
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
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
13 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,641
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

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
  • 30.4k
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
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
  • 30.4k
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
  • 86.2k
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
  • 86.2k
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
  • 55.4k
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
  • 55.4k
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,360
7 votes
Accepted

Is there a drawback of setting a too high gas limit for a transaction?

If the transaction executes your on-chain function, which you obviously have 100% confidence of for not spending an excessive amount of gas, then the only drawback is that the gas limit that you set ...
goodvibration's user avatar
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
  • 86.2k
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.8k
6 votes
Accepted

What is the relationship between Gwei and gas?

Gas is needed by miners to execute a transaction. The more complicated a transaction is, the more gas they will need. When you send a transaction, you (or your wallet program) has to configure two ...
Jesbus's user avatar
  • 10.5k
6 votes
Accepted

Truffle - test - how to get more than 10 accounts?

Truffle tests run ganache-cli behind the scene in default mode (10 accounts). But if you run yourself ganache-cli with x accounts generated, you will have access to all of these accounts from your ...
Greg Jeanmart's user avatar
6 votes

Gas for view functions

View will not cost gas only if called from outside the network, that is if a function in a contract is view and is called from another contract it will cost gas. The reason it will not cost gas if ...
Jaime's user avatar
  • 8,360
6 votes

Truffle and Ganache - do I need to set the same gas-price and gas-limit in both of them?

TL;DR: Yes you can use the same value. Here is why: Ganache Ganache is a local test Blockchain. -l or --gasLimit is the block gas limit (total amount in gas unit that can fit in a block). Let's ...
Greg Jeanmart's user avatar
5 votes
Accepted

How to call Library Function from a Contract? => [error] The contract code couldn't be stored, please check your gas amount. undefined

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 ...
BokkyPooBah's user avatar
  • 40.3k
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
  • 86.2k
5 votes

Gas limit exceeded on private chain

Don't change the genesis file, as it changes the dynamics of the blockchain. Geth has a --targetgaslimit flag that will cause the miner to converge towards a specific number opposed to the hard coded ...
q9f's user avatar
  • 33k

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