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
239
votes
8answers
178k 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?
83
votes
9answers
20k 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?
54
votes
4answers
15k 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 ...
51
votes
2answers
30k 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?
44
votes
3answers
12k 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 ...
40
votes
2answers
19k 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?
39
votes
3answers
18k 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:...
38
votes
3answers
17k 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 ...
37
votes
4answers
69k 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 ...
27
votes
1answer
8k views

What is and how to calculate 'cumulative gas used'?

When I see transactions in Etherscan (e.g., 0x7eb9a7454f9cd2f39a7ea7c6212833673165b35f352127ffb337df866897eb73), I see the field Cumulative Gas Used which isn't present in web3 response. In general, ...
26
votes
6answers
18k views

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

I'm trying to deploy a sample contract (following this guide) but I'm receiving an error of not enough gas. I changed the numbers a little but could not fix it. I saw this question in stack exchange ...
26
votes
1answer
9k 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)?
24
votes
3answers
7k 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 ...
24
votes
3answers
58k 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; ...
24
votes
2answers
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?
23
votes
2answers
2k 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 ...
22
votes
6answers
8k views

How to remove gas system from ethereum

I'm testing Ethereum with a complex contract which requires quite a lot of gas. And I'm testing (and will be running) a private network with controlled miners, so I don't need them getting any reward, ...
22
votes
1answer
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 ...
21
votes
4answers
11k 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 ...
21
votes
5answers
40k 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, ...
21
votes
3answers
31k 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: ...
20
votes
4answers
9k 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)...
20
votes
1answer
7k views

Are gas limit in transaction and block gas limit different?

What does gas limit mean? Are there two meanings of gas limit? gas limit in a transaction block gas limit
19
votes
2answers
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 ...
18
votes
2answers
25k 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 ...
18
votes
5answers
10k 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 ...
18
votes
1answer
7k views

Does it cost more gas to call another contract's functions in solidity?

I would like to break my code up into multiple contracts, but I'm afraid of this increasing the gas fees. Does an external function call cost more gas than an internal call to a function within the ...
17
votes
2answers
4k views

Where does the consumed ether/gas go?

I'm a bit new to ethereum and I'm finding it a bit difficult to understand how gas and Ether relate. So every call we do to a smart contract costs gas. Where does the gas that the user pay goes to? ...
17
votes
3answers
8k views

Could we 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 ...
17
votes
1answer
7k 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 ...
16
votes
3answers
11k 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() ...
16
votes
1answer
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 &...
16
votes
1answer
7k views

How much does it cost to use a contract?

Still new to ethereum and would like to know the price for a contract.
16
votes
1answer
2k views

Execution of Fallback function with more 2300 gas

I have tested a contract having a fallback function which updated a state variable (cost 5000 gas). I sent an amount of Ether to this contract with 100000 gas limit. The transaction is valid. As ...
15
votes
2answers
5k 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 ...
15
votes
2answers
5k 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 ...
15
votes
5answers
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?
15
votes
2answers
2k views

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

I've noticed this number at least in two places: On the Ethereum Network Status web page. In the sources of pyethereum. The number looks suspiciously familiar, and I keep asking myself: "Where ...
15
votes
3answers
1k views

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

If a contract call predictably requires 41043 of gas to be processed as estimated by estimateGas, how come I need to specify gasLimit of ~70000 to be processed?
14
votes
3answers
805 views

Why does Ethereum have gas?

Why does Ethereum have gas? What other approaches could Ethereum have used to work around the Halting Problem?
14
votes
5answers
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]; //...
13
votes
2answers
6k 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 ...
13
votes
2answers
1k 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 ...
13
votes
3answers
5k views

Do users of ERC20 coins need to hold Ether?

Suppose there exists Fancycoin, an ERC20 altcoin which has some functionality implemented by the EVM. It does some nontrivial things that take up gas. According to my understanding, I can receive ...
13
votes
4answers
34k views

How are Ethereum transaction costs calculated?

I'm in the process of learning blockchain technology for a client of mine. I understand the concept of "gas" in computational costs. We are looking at creating a crypto-currency as an alternative ...
12
votes
2answers
896 views

What happens when two smart contracts recursively call each other?

As I understand it, a smart contract can "call" other smart contracts. So what happens when two smart contracts call each other in a recursive loop? Does the whole network break down and die?
12
votes
1answer
419 views

How growing contract storage increases the gas spending?

I have some further questions about this and this threads. For simplicity, let's imagine that I want to create a cryptocurrency on top of ethereum. The contract that "handles" this cryptocurrency ...
12
votes
2answers
7k views

How to whitelist up to 50k addresses in a single contract?

What is the best practice in whitelisting a large amount of addresses in a contract. For example, if I wanted to include 50k addresses into a mapping that will reflect true for only the 50k addresses, ...
12
votes
2answers
635 views

Can I send gas to another user?

Gas is purchased using Ether, does that mean I can send gas as a separate coin?
11
votes
2answers
3k 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?

1
2 3 4 5
28