Ethereum Gas Discussion

Welcome to the thread about Gas. Here you can discuss everything about Gas and potential problems that you might stumble upon.

2 Likes

Can we limit string sizes by using an array of characters or something?

1 Like

Yes, you can read more about that here https://medium.com/@cryptopusco/bytes-and-strings-in-solidity-f2cd4e53f388

3 Likes

I would appreciate a bit more elaboration on the EVM and how the code in the smart contracts is actually executed (where is the code processed? / who does this? / what check are there in place to ensure correct code is executed?)

Thanks

2 Likes

Hi, that’s a good question. Fortunately, there is plenty of great material on the EVM. You can find a good read here https://www.mycryptopedia.com/ethereum-virtual-machine-explained/

2 Likes

awesome. now I can make the contract as cheap as possible!
gonna research more on how solidity handles memory.

GreetZz

1 Like

Hi Filip,
You are mixing bytes and bits in the lessons… uint8 is 8 bits or one byte.
https://solidity.readthedocs.io/en/v0.4.24/types.html#integers

Yes, you are completely right. Did I misspeak in the video?

I’m not sure if it’s best to start a new thread or continue here.

After watching the Gas video in the Ethereum 101 course I am left with a bunch of questions.
I understand that operations have relative costs expressed as gas and that gas limits can be set by miners. What I’m still a bit foggy on is how the gas and Eth ratio is determined and how miners are compensated for gas use.
Miners earn Eth from the gas paid by those using the EVM, right? When I send a transaction I usually use the default gas settings. If I put it up, it would cost more, right, but how much?
So how does the system respond when the price of Eth changes in relation to the USD? Say as an example, Eth price doubles, miners should reduce their minimum gas limit so that people using the EVM can afford to run their operations? What would happen if they didn’t? They would just earn the block reward?

Good questions! I hope I can clarify :slight_smile:

The gas limit is separate from the gas price. The amount of gas consumed by, let’s say a smart contract function called X, will always be the same, regardless of ETH/USD price and regardless of gas price. Because the amount of gas needed for a set of operations is defined in the EVM.

When you make a transaction or a function call, you can set the gas limit. That is how much gas are you willing to consume. You might not know exactly how much gas the tx will cost, unless you know the code in exact detail. So you can set an upper limit on how much gas you will allow this tx to consume. This has nothing to do with the price of gas or the price of ETH/USD.

You can also set the gas price when you make a transaction. This is how much you are willing to pay for each unit of gas your transaction consumes. How much the tx cost in ETH will be determined by the gas consumed x gas price. This is what the miner gets.

This price is determined purely by market forces. Just like the tx fee in Bitcoin. If the blocks are crowded and there are a lot of transaction in the eth network that wants to be included into blocks, the price will rise because miners will pick the ones generating most income for them. If there are very few tx in the network, the price will be low. But you are right that if the ETH/USD price would go up a lot, the gas/eth price would probably go down since most miners pay there bills in fiat any way. But it will be a free market competition between miners.

Did that make it clearer?

1 Like

Yes, you did. Thank you so much for your reply. I’m quite enjoying the course so far.

Hi all,

i have a beginners question about gas usage: Why is there a difference between the ‘gas used by the transaction’ and the gas used by the actual function calls?
Consider for instance the following example transaction on the kovan test net:

In the “Overview” Tab you can see that the transaction used 484k gas (the gas limit was 600k). However if you look at the “Internal Txns” and scroll to the bottom one can actually see that only 25k gas of the 600k gas in the beginning are left. What explains the difference?

To make things worse, a transaction which uses only slightly more gas than the one shown above indeed runs out of gas and fails. (see, e.g., https://kovan.etherscan.io/tx/0xab765e68b854e6a538f5eed45ffdc7b56578d2e2322f863700e90624c5ce2ae4#internal, which fails at the very last transaction…)

It seems that the “Gas Used by Transaction” value shown in the usual blockexplorers is flawed… but more likely i am simply missing something basic here.

Thx in advance!
Philipp