Guide to Ethereum: What is Gas, Gas Limit and Gas Price?

0

[ad_1]

This article breaks down the concept of gas, gas limit and gas price, which is a central feature of the Ethereum (ETH) Blockchain and ecosystem.

gas, gas limit, gas price, ethereum, ETH

If you’ve performed a simple transfer of Ether (ETH) from one place to another or participated in an Initial Coin Offering (ICO), then chances are you’re exposed to the concept of gas in the Ethereum network. Understanding the mechanics of gas and the associated terms “gas limit” and “gas price” is a crucial element to executing your ETH transactions. But before delving into the details of gas, it’s important to have a basic understanding of Ethereum.

(Read more: Coins, Tokens & Altcoins: What’s the Difference?)

Ethereum Basics

Ethereum is a giant network consisting of a huge number of computers connected together. This large, interconnected web of computers is called the Ethereum Virtual Network (EVN) essentially a global, “supercomputer” where all transactions occurring in the Ethereum network are updated and recorded into each computer. Ether (ETH) is the native currency of the Ethereum blockchain and is used as the “fuel” for the network. ETH is not to be confused with Ethereum Classic; the latter is a fork of the Ethereum Blockchain. Here’s a guide to understanding forks, hard forks and soft forks.

A revolutionary functionality of the Ethereum blockchain was the introduction of smart contracts. Smart contracts are any contracts that have been pre-programmed with a set of definitive rules and regulations that are self-executing, without the need of any intermediaries. Therefore, with any given inputs, there will be a known output. As they say:

Code is King

Here’s simple (hopefully!) breakdown of a smart contract:

gas, gas limit, gas price, ethereum, ETH

Why Is Gas Needed?

Ether tokens (ETH) are publicly traded on exchanges and its market price can fluctuate rapidly. The creation of gas units is to separate the cost of computation work in the Ethereum network from Ethereum’s volatile market price, as the cost of computation DOES NOT change rapidly. Imagine paying a flat fee calculated directly in Ether when it’s market price was $10 and to send an ETH, you needed to pay half an ETH ($5) a year ago. Now, the price of ETH is at $1,000. Would you want to pay $500 (0.5 ETH) for exactly the same transaction? That’s why the gas system was created. (See also: Bitcoin vs Alt Coins Returns: Comparison of Gains Between Bitcoin & Altcoins Investing)

What is Gas?

Gas is a unit of measuring the computational work of running transactions or smart contracts in the Ethereum network. This system is similar to the use of kilowatts (kW) for measuring electricity in your house; the electricity you use isn’t measured in dollars and cents but instead through kWH or Kilowatts per hour.

It is important to understand that different kinds of transaction require a different amount of gas to complete. For instance, a simple transaction of sending ETH from one place to another cost 21,000 Gas while sending ICO tokens from your MyEtherWallet (MEW) wallet costs much more due to higher levels of computation ended. Here’s a guide on opening a MEW wallet, which is a wallet that supports ETH and ERC-20 coins.

Execution of the smart contracts is done by a miner, who spends their own time, electricity and computing hardware to execute the codes and finalize the transaction

Gas Limit

Gas limit refers to the maximum amount of gas you’re willing to spend on a particular transaction. A higher gas limits mean that more computational work must be done to execute the smart contract. A standard ETH transfer requires a gas limit of 21,000 units of gas.

The more complex the commands you want to execute, the more gas you have to pay. You can see this in action when participating in an ICO that requires you to send ETH into its smart contract or when you want to withdraw your ICO coins to an exchange; the fees of transfer are much higher than the default 21,000 gas limit. This is because the smart contracts of an ICO possess much more complex codes and require much more computation than a simple ETH transfer.

Gas limit acts as a safety mechanism to protect you from depleting your funds due to buggy codes or an error in the smart contract. As an analogy, gas limit is similar to your car’s fuel tank capacity.

(See more: Guide to Valuing Cryptocurrency: How to Value a Cryptocurrency)

What if You Specify Too Little Gas?

Your transaction will be initially executed by the miners, but once gas runs out the miners will STOP performing work on your transaction. The blockchain will record the transaction as “Failed”, and your ETH will still be in your wallet since there was insufficient gas to fully execute the transfer. The gas used for the failed transaction will be kept by the miners for their work and you WILL NOT get it back. Here’s what’ll happen if you specified too little gas.

gas, gas limit, gas price, ethereum, ETH

You don’t have to worry about setting the gas limit value as MyEtherWallet (MEW) and Metamask would automatically set the default gas limits for the types of transactions you’ll engage in.

Gas Price

Gas price refers to the amount of Ether you’re willing to pay for every unit of gas, and is usually measured in “Gwei”. An analogy for gas price – relating to the previous analogy for gas limits – is that it is similar to the cost of each litre of fuel that you’re paying for filling up your car.

gas, gas limit, gas price, ethereum, ETH

Wei is the smallest unit of Ether, and a Gwei consists of a billion wei. Before entering you’re the gas price that you want to set, it’s always good to look at current gas prices from ETH Gas Station. Here’s what it will look like:

gas, gas limit, gas price, ethereum, ETH

Here’s a breakdown of the terms:

Std (Standard) Cost for Transfer: Average fees that users pay to transfer ETH – in USD value – for a standard priority transaction (usually a waiting time of fewer than 5 minutes)

Gas Price Std (Gwei): Average fees that users pay to transfer ETH – in Gwei value – for a standard priority transaction (usually a waiting time of fewer than 5 minutes)

SafeLow Cost for Transfer: Average fees that users pay to transfer ETH – in USD value – for a low priority transaction (usually a waiting time of fewer than 30 minutes)

Gas Price SafeLow (Gwei): Average fees that users pay to transfer ETH – in USD value – for a low priority transaction (usually a waiting time of fewer than 30 minutes)

Median Wait (s): Average waiting time for a single transaction in seconds

Median Wait (blocks): Average waiting time for a single transaction in blocks

(Read more: Evolution of Cryptocurrency: What is Cryptocurrency?)

Can I Speed Up My Transaction?

If you’re wondering what’s the difference between a low priority and a standard priority transaction, here’s a table extracted from ETH Gas Station to help you understand better:

gas, gas limit, gas price, ethereum, ETH

You can actually choose the priority level of your transaction. Miners will “work on” and execute transactions that offer a higher gas price, as they’ll get to keep the fees that you pay. Therefore, they will be incentivized to prioritize transactions that have a higher Gwei.

If you want your transaction to be executed at a faster speed, then you have to be willing to pay a higher gas price. You’re essentially “jumping the line”, beating everybody that paid a lower gas price. Based on the above table, you have to pay 8 Gwei if you want your transaction to be finalized within 2 minutes. It all depends on your urgency.

(Read also: Guide to Cryptocurrency Taxes: A Guide to Common Tax Situations)

Putting It All Together

Let’s take a look at an example of an Ethereum transaction to see how the concepts of gas, gas limit and gas price come together:

gas, gas limit, gas price, ethereum, ETH

Looking at this transaction at Etherscan, we can see the breakdown of all terms associated with gas. Here’s what they mean:

Gas Limit: Maximum amount of gas that a user will pay for this transaction. The default amount for a standard ETH transfer is 21,000 gas

Gas Used by Txn: Actual amount of gas used to execute the transaction. Since this is a standard transfer, the gas used is also 21,000

Gas Price: Amount of ETH a user is prepared to pay for each unit of gas. The user chose to pay 8 Gwei for every gas unit, which is considered a “high priority” transaction and would be executed very fast

Actual Tx Cost Fee: This is the actual amount of fees that the user will pay for the transaction in Ether value (USD value is in brackets). Not bad; the user paid a total of 14 cents for his ETH to be transferred in less than 2 minutes!

In summary, the ultimate formula to calculate the amount of fees you’ll end up paying for a transaction is:

Transaction (Tx) Fees: Gas Used by Txn * Gas Price

From the above example, we can see that the actual gas consumed in executing the transaction is 21,000 gas while the gas price chosen by the user is 8 Gwei (0.000000008 ETH). Multiply both figures together and you’ll get the actual cost of executing the transaction, amounting to 0.000168 Ether (USD $0.14).

It is important to note that the gas limit can be (and is usually) more than the actual gas used in the transaction. In times of an ICO, the average gas price will tend to be exponentially higher as people will be rushing to participate in the ICO. This would lead to more people increasing their gas prices to have a better chance of confirming their ICO transaction.

Ethereum Sharding Guide: Ethereum’s Scalability Solution

Ethereum Sharding: This portion was added by Shawn Dexter from MangoResearch – breaking down Ethereum’s scalability solution called Sharding, using a simple analogy.

ethereum's scalability solution, Ethereum, sharding, Ethereum sharding, scalability

The demand for scalability is becoming increasingly urgent. The Cryptokitties incident demonstrated how quickly the Ethereum network can clog-up. While many in the community are excited about Ethereum’s Sharding, there are just as many who struggle to understand how sharding will help Ethereum scale. Here’s a simplified guide to Ethereum for those who want a refresher.

In this post, I will attempt to explain Ethereum’s sharding using a simple analogy.

Understanding The Problem

One of the major problems of a blockchain is that an increase in the number of nodes reduces its scalability. This may seem counterintuitive to some people. (Read more: Evolution of Cryptocurrency: What is Cryptocurrency?)

“More nodes = more power. So more speed, right?”

Not exactly.

One of the reasons a blockchain has its level of security is because every single node must process every single transaction. This is like having your homework assignment checked by every single professor in the university. While this may ensure that your assignment is marked correctly, it will also take a really long time before you get your assignment back.

Ethereum faces a similar problem. The nodes are your professors. Each transaction is your assignment.

Sure, we can reduce the number of professors (nodes) until we are satisfied with the speed. But as the assignment (transaction) backlog increases, we will need to further decrease the number of professors. This will eventually lead us to rely on a few “trusted” group of professors. A centralized group.

This defeats the ideology of blockchain decentralization.  It’s much easier to compromise/corrupt a smaller group of professors (nodes) than the entire university (the entire network). As a result, we sacrifice security in an effort to scale. (See also: What’s the Difference Between Ethereum and Ethereum Classic?)

ethereum's scalability solution, Ethereum, sharding, Ethereum sharding, scalability

What is “Sharding”?

With the problem and limitations understood, we now pose a question:

Can we have a system that has a sufficient number of “professors” (nodes) to still maintain the security –  while being small enough to increase the speed at which your assignments are returned (throughput of the network)?

Essentially, we are conceding that we can’t “max-out” on all three of the attributes: Scalability, Security, Decentralization.  But, can we have just “enough” decentralization & security so as to achieve more scalability?

Sharding is Ethereum’s answer to this question.

Ethereum Sharding: Think of Sharding as simply a fancy way of saying, “let’s break down the network into smaller groups/pieces”.

Each group is a shard. A group/shard consists of nodes and transactions.

So in our professor analogy, a shard would consist of a group of professors and assignments. Now, instead of a professor having to correct the assignments across the entire network, he would be only responsible for the assignments within his shard(group).

This greatly reduces the number of transactions (assignments) each node (professor) has to validate. (See also: Understanding Cryptocurrencies: Game of Thrones Edition)

Ethereum Sharding – Structure

Okay, so I may have oversimplified a tiny bit. But now that you understand the gist, you’ll understand this part a lot easier.

In each shard/group, we have nodes that are assigned as “Collators”.  Collators are tasked with gathering mini-descriptions of transactions & the current state of the shard. In our analogy, you can think of Collators as Teacher’s Assistants. All the TA’s in shard/group do the first run through of all the assignments within the shard.

Finally, we have super-nodes. Each super-node receives the collations created by the collators of each shard. They then process the transactions within those collations. Furthermore, they maintain the full-description/state data of all the shards – which they get from the collators as well.

You can probably see the benefits of this structure. The number of nodes that process every single transaction would be greatly reduced, and thus increase overall throughput.

Sharding Outlook Conclusion

Sharding is a smart approach to tackling the blockchain scalability problem. However, it’s not without its drawbacks. Because of its structure, it’s easier to compromise a shard within the system.

This is one of the driving reasons behind Ethereum’s switch to Proof Of Stake. Proof Of Stake helps mitigate this security vulnerability that comes with Sharding. But for the sake of brevity,  we will discuss that in a future post.

Beneficial Resources

If you’re starting your journey into the complex world of cryptocurrencies, here’s a list of useful resources and guides that will get you on your way:

Crypto Beginners Guide, 5 Things Crypto Newbies Should Know, should know, crypto, guide

Trading & Exchange

Wallets

Read also: A Guide To Fundamental Analysis For Cryptocurrencies and Cryptocurrency Trading: Understanding Cryptocurrency Trading Pairs & How it Works

Enroll in our Free Cryptocurrency Webinar now to learn everything you need to know about crypto investing.

Get our exclusive e-book which will guide you on the step-by-step process to get started with making money via Cryptocurrency investments!

You can also join our Facebook group at Master The Crypto: Advanced Cryptocurrency Knowledge to ask any questions regarding cryptos!

[ad_2]

Source link

You might also like
Leave A Reply

Your email address will not be published.