Questions tagged [gas]

Gas is a 'sub-currency' which enables the EVM and Ethereum's decentralised computer to run -- with each operation, an amount of gas (proportional to the computational effort required to perform the operation) is consumed.

Filter by
Sorted by
Tagged with
260 votes
9 answers
195k views

What is meant by the term "gas"?

An Ethereum application that I want to use talks about needing "gas" to run. What is gas, and where do I get it?
Jeff Coleman's user avatar
  • 22.1k
91 votes
9 answers
25k views

Can contracts pay the gas instead of the message sender?

Is it possible for a contract to pay the gas costs (or part of it) that result from the contract being called? Or does the sender of a message always pay the resulting gas costs no matter what?
mKoeppelmann's user avatar
  • 7,626
57 votes
2 answers
38k views

Is there a limit for transaction size?

Is there a theoretical limit for transaction data size when you send a transaction to Ethereum network? Ref. Is there a (theoretical) limit for amount of data that a contract can store?
Satoshi Nakanishi's user avatar
29 votes
3 answers
12k views

How do gas refunds work?

Gas refunds are provided when clearing storage or calling SELFDESTRUCT on contracts. The Yellow Paper mentions that refunds are "being capped up to a maximum of half...". What exactly is ...
eth's user avatar
  • 85.7k
21 votes
4 answers
12k views

How can the transaction status from a thrown error be detected when gas can be exactly the same as the gasUsed for a successful transaction?

This question arose from answering Transaction Status. In the following example, I am sending gas of 21,000 (the amount required for a regular transaction). In this situation gas == gasUsed, and so ...
BokkyPooBah's user avatar
  • 40.3k
43 votes
3 answers
21k views

What are the limitations to estimateGas and when would its estimate be considerably wrong?

web3.eth.estimateGas and JSON-RPC estimateGas can be used to see how much gas should be specified for a transaction, before crafting the transaction. Since it is an estimate, are there any ...
eth's user avatar
  • 85.7k
16 votes
1 answer
8k views

How much does it cost to use a contract?

Still new to ethereum and would like to know the price for a contract.
Patoshi パトシ's user avatar
19 votes
2 answers
31k views

how to estimate gas cost?

I have a function that iterate through an array, which could cost a lot of gas. But I still want to test out the estimate gas cost, then decide if I should maintain the design or not. function ...
dome some's user avatar
  • 319
24 votes
5 answers
15k views

How to make someone else pay for Gas?

My understanding is that msg.sender pays the gas fee. Can a smart contract be written in such a way that it's always the contract owner who pay the fees? As an example, in an ERC20 token when someone ...
eth.block's user avatar
  • 431
74 votes
5 answers
28k views

Why does uint8 cost more gas than uint256?

contract A { uint8 a = 0; } costs 20150 + 2000 gas during creation. as compared to contract A { uint a = 0; // or uint256 } costing 5050 + 2000 gas during creation It is odd that a variable ...
uzyn's user avatar
  • 1,100
49 votes
3 answers
14k views

How were gas costs chosen for the Ethereum Virtual Machine instructions?

Different instructions of the EVM have different associated gas costs -- you can look at the list of the gas-prices in the appendix G of the yellow paper. While the rough magnitudes of those numbers ...
Kostya's user avatar
  • 866
18 votes
4 answers
8k views

How can I call a constant function without spending any gas inside a transaction function?

I have a sorted linked list that contains around 1000 items. When I receive a new item my goal is to push the item to the list keeping the sorted order. So if I receive very small value, I am required ...
alper's user avatar
  • 8,395
58 votes
6 answers
118k views

error: replacement transaction underpriced

Im trying to send a raw transaction using web3 to ropsten testnet and Im getting this error: replacement transaction underpriced where sometimes my tx works and sometimes I get this error. my tx ...
Ernane Luis's user avatar
20 votes
2 answers
9k views

Is transfer() still safe after the Istanbul update?

In other words, is using transfer() safe? function transfer(address contractB) public { contractB.transfer(1000); //balances[msg.sender] -= 1000; } How about using call.gas? function ...
Robert Ggg's user avatar
46 votes
3 answers
25k views

Is there a table of EVM instructions and their gas costs?

The EVM instructions are in the yellow paper, or they are summed up in this answer. But their gas costs are not there. Where can I find a list of all instructions with their associated gas costs?
comodoro's user avatar
  • 1,202
19 votes
2 answers
6k views

Where does the number 21000 come from for the base gas consumption in Ethereum?

Can you break it down in terms of the cost of opcodes?
Hanhan Li's user avatar
  • 291
9 votes
4 answers
3k views

best practice for airdrops and gas usage

I tried to write an airdrop contract which takes a list of recipients and a list of balances and then can be commanded to airdrop all at once. With code below I can launch a single transaction able to ...
Davide C's user avatar
  • 896
21 votes
3 answers
34k views

Can I set the gas price to whatever I want?

The default gas price is 0.02e12 Wei. But while creating transactions on the command line or Geth's Javascript console you can define your own gasPrice: web3.eth.sendTransaction({/* ... */, gasPrice: ...
q9f's user avatar
  • 32.9k
22 votes
2 answers
13k views

View/Pure Gas usage - Cost gas if called internally by another function?

I know similar questions have been asked before however I could not find an good explanation for the following, In one of the tutorial it says: Pure and View functions don't cost any gas to call ...
Mustafa Caglar's user avatar
17 votes
2 answers
2k views

Can Solidity view/pure functions be arbitrarily complex?

Non-constant functions are limited in computational complexity by the block gas limit. I assume, but am not sure, that this does not apply to view/pure functions. Are view/pure functions in any way ...
SCBuergel's user avatar
  • 8,774
12 votes
1 answer
8k views

Is there any profit from using pure and view functions modifiers?

I have a function that does not read or modify contract's state: contract C { function add(uint a, uint b) public returns (uint) { uint res = a + b; return res; } } Does it ...
30mb1's user avatar
  • 369
28 votes
2 answers
21k views

How do I know how much gas to use when calling a contract?

When I am calling (sending a transaction to) a contract how do I determine how much gas to use? Is there a way to calculate this upfront & what happens if I send too much / too few gas?
J-B's user avatar
  • 8,941
21 votes
4 answers
10k views

How does one contract send ether to another contract with more than 2300 gas?

I want one contract to collect a certain amount of finney before sending it to another contract, but I can't simply send in with C2.send(thisMuch). function() { Dividend m = Dividend(dividendAddr)...
Sileniced's user avatar
  • 537
19 votes
2 answers
2k views

Can a contract's internal storage keep increasing forever?

In other words, is there a limit on the amount of storage a contract can hold? Suppose a field is an Array for instance, and the contract has a method for adding items. Can I keep calling the ...
Fernando Tiberti's user avatar
18 votes
1 answer
8k views

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

As gas cost can only be estimated until the transaction is executed against the actual contract state at the time of execution on the blockchain, what happens if transaction runs out of gas before the ...
zanzu's user avatar
  • 5,360
17 votes
1 answer
2k views

How does EIP 150 change the call depth attack?

It seems that EIP-150 introduced a more expensive gas based restriction on the call stack and completely removed the previous 1024 hard stack limit. Is this true? It seems it took cues from EIP-90 &...
Simon de la Rouviere's user avatar
15 votes
5 answers
5k views

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

This keeps coming up on the gitter forums so I thought I'd ask and answer this question: How do you know when you've run out of gas?
Paul S's user avatar
  • 4,271
14 votes
5 answers
3k views

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

I am using the below code to create the contact it give the error: Error: The contract code couldn't be stored, please check your gas amount. Code: primaryAccount = web3.eth.accounts[0]; //...
Veera Sarma's user avatar
7 votes
4 answers
2k views

If everyone runs the same transaction, why does only the miner get gas?

If I understand Ethereum correctly, the result of a transaction is known and verified by everyone because everyone runs the code using their own copy of the blockchain. If that is indeed the case, why ...
David Deutsch's user avatar
29 votes
3 answers
81k views

What does "intrinsic gas too low" mean?

I'm running the Mist wallet, and I've deployed this contract to testnet (from https://ethereum.stackexchange.com/a/179/520) : contract Notary{ struct Document { uint timestamp; ...
Fernando Tiberti's user avatar
23 votes
2 answers
3k views

What type of operations have negative gas costs?

I understand that some operations cost negative gas because they free up space on the blockchain, such as selfdestructs. What are all the operations that can have negative gas? Does this only occur ...
DirtStats's user avatar
  • 656
10 votes
3 answers
13k views

How do I send the entire ether balance from one account to another account?

I'm trying to use web3 to transfer all (or as much as I can) of the balance of an account to another account. Here is the code I have so far: var sender = web3.eth.accounts[0]; var receiver = web3....
Webeng's user avatar
  • 895
7 votes
1 answer
3k views

Default Value for gas in sendTransaction

What is the default value for gas in sendTransaction api? Suppose I don't specify gas parameter in the sendTransaction api, what will be used? Also, will this vary if it is a contract transaction ...
Aman C's user avatar
  • 983
4 votes
2 answers
4k views

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

Pardon me if this question seems a bit naive. I have written a smart contract (for proof of existence) and simulating it in Ganache. Inside it I have logic to store data in a mapping created between ...
tanmay's user avatar
  • 428
3 votes
2 answers
1k views

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

I'm executing transactions on mainnet with a NodeJS script: async function send(web3, transaction, destAddr, gasPrice, privateKey) { const options = { data : transaction.encodeABI(), ...
goodvibration's user avatar
3 votes
1 answer
3k views

Which miner gets the gas fee for each transaction? [duplicate]

I'm guessing that miners are randomly selected, but I'm curious as to which miner receives the fee for gas paid for each transaction? In hindsight, the answer to this question is obvious: of course ...
JohnAllen's user avatar
  • 1,318
22 votes
1 answer
3k views

What were the key assumptions and analyses that went into setting Ethereum's gas price?

Frontier was launched with a default gas price of 0.05e12 wei. In Homestead, the default was reduced to 0.02e12 wei. If this gas price is too low and operations on Ethereum are too cheap, for ...
eth's user avatar
  • 85.7k
21 votes
5 answers
42k views

How to know if a transaction went through or not? (out of gas)

Apparently when sending transactions from an Account instead of a Wallet, the gas spent is small (21K), and not enough to send ether to a Contract Wallet (out of gas, so to speak). When this happens, ...
knocte's user avatar
  • 1,929
18 votes
3 answers
16k views

Contract address.transfer method gas cost

Who will pay the gas in the following scenario? Lets say we have the following simple function. That sends an amount from the contract back to the sender.. just an example. function withdraw() ...
Cody Popham's user avatar
17 votes
2 answers
7k views

Ethereum event log maximum size

I'm thinking of storing some data in logs by emitting events but I cannot easily find the answers to the following questions: What is the total size limit of one event? Can I store lots of string32 ...
Aldekein's user avatar
  • 402
11 votes
1 answer
2k views

Is the cost of updating storage different than the cost of adding to storage?

Do these have a separate cost? sstore(1, 10) # first time adding a value to storage with this key sstore(1, 20) # changing the value in storage. I looked for a list of gas costs / opcodes, and the ...
Broseph's user avatar
  • 695
10 votes
4 answers
21k views

How to increase gas limit in block using geth?

When I try to execute methods from my smart-contract, I get limited by the gas limit in a block and can't do anything. How to change the gas limit in the block?
Andrei Zolin's user avatar
8 votes
3 answers
13k views

Getting infinite gas estimates for simple functions

I am testing out solidity in remix ide using simple contracts. This is the contract that I wrote: contract mortal { address owner; function mortal() { owner = msg.sender; } function kill(){ ...
Ahsan Jamal's user avatar
6 votes
3 answers
4k views

Block gas limit exceeded when compiling contract Solidity browser

Using Solidity Browser ( https://ethereum.github.io/browser-solidity/ ) to mine a contract on testnet with injected web3 and metamask account, throws this error: callback contain no result Gas ...
Juan Ignacio Pérez Sacristán's user avatar
5 votes
3 answers
2k views

Does an SSTORE where the new value is the same as the existing value cost gas?

For example (in Vyper): @external def foo(bar: uint256): self.baz = bar foo(3) foo(3) # Is the gas cost here still 5000? Is it better to do this instead? def foo(bar: uint256): if self.baz != ...
Dylan Kerler's user avatar
5 votes
2 answers
14k views

What is the size (bytes) of a simple Ethereum transaction versus a Bitcoin transaction?

Alice owns an empty Ethereum wallet. Receives 1 ETH then sends 1 ETH to Bob. Alice owns an empty Bitcoin wallet. Receives 1 BTC then sends 1 BTC to Bob. What are the transaction sizes in bytes (...
lumierre's user avatar
4 votes
1 answer
21k views

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

What is the correct algorithm to calculate gas limit for transaction with data in Ethereum?
Slava Fomin II's user avatar
2 votes
1 answer
5k views

Why does the transaction exceed block gas limit? [closed]

When I try sending ether to another account, I keep getting the message "Exceeds block gas limit". I changed the gas amount from 5,000 to 100,000 but nothing else happened. Why does the transaction ...
rethsid's user avatar
  • 1,898
46 votes
3 answers
22k views

How to write an optimized (gas-cost) smart contract?

As we all know, there are many factors that determine a good smart contract, such as: Security: it has minimal/zero vulnerability so they cannot be exploited by an adversary. Immune to Attacks. Cost:...
Aydin's user avatar
  • 2,117
28 votes
1 answer
11k views

What is the cheapest hash function available in solidity?

AFAIK there are 3 hash functions to choose from in solidity (sha3, sha256, and ripemd). sha3 is native while the others use precompiled contracts. Which one of these is cheapest (in terms of gas)?
Akhil F's user avatar
  • 1,928

1
2 3 4 5