Ethereum! A door of possibilities

In the last article we talked about what blockchain technology is and how it functions. We also saw some of the advantages of blockchain over the traditional centralized system. In this article, we are going to shift our focus a bit from the traditional “Bitcoin” and focus more on Ethereum technology.

What is Ethereum?

Although commonly associated with Bitcoin, blockchain has many other applications that go beyond just digital currencies. According to ethereum.org, Ethereum is a decentralized platform that runs smart contracts. At its simplest, it is an open source platform based on blockchain technology that enables developers to build decentralized applications.

Like Bitcoin, Ethereum is also a distributed public blockchain network. Though Bitcoin and Ethereum may give the same idea, they substantially differ in purpose and capability. Putting it in Layman’s terms, Bitcoin offers one particular application of blockchain, a peer to peer electronic transaction system. Where Bitcoin blockchain is used to track and store the information about the transactions among the Bitcoin holders, Ethereum blockchain focuses on running the programming code of any decentralized application.

Ethereum Virtual Machine

Ethereum Virtual Machine or EVM is the heart of the Ethereum system. Ethereum is programmable blockchain. It allows its users to create their own operations of any complexity that they wish. This is how Ethereum serves as a platform for many different types of decentralized blockchain.

EVM executes code of arbitrary algorithmic complexity. In computer science terms, Ethereum is “Turing complete”. Developers can create applications that run on the EVM using friendly programming languages modeled on existing languages like JavaScript and Python.

Ether and its uses

In the Ethereum blockchain, miners work to earn Ether (ETH), a type of crypto token that fuels the network. Beyond a tradeable cryptocurrency, Ether is also used by application developers to pay for transaction fees and services on the Ethereum network. Besides being used for fueling the network, Ether can also be transferred between accounts and used to compensate participating mining nodes for computations performed (Proof of Work).

Smart Contract

Smart contract is a computer protocol used to facilitate, verify or enforce the negotiation or performance of a contract. They allow the performance of credible transactions without third parties.

Now that we have a basic picture of what Ethereum is, we can dive into the depths of how this technology works.

Ether is the fundamental cryptocurrency for operation on Ethereum blockchain. It is used to pay GAS , a unit of computation used in transactions and other state transitions. Thus, to understand the working of Ethereum, we need to understand what is GAS and how is it used?

What is GAS?

“GAS” is the name for a special unit of Ethereum blockchain fuel, which is used to measure how much “work” an action or a set of actions takes to perform. It is a unit for measuring the amount of work done for a particular activity.

For example, to calculate one Keccac256 cryptographic hash, it will take about 30 gas units each time the hash is calculated, plus a cost of 6 more gas for every 256 bits of data being hashed. Every operation that can be performed by a transaction or contract on the Ethereum platform costs a certain number of GAS units.

It helps to ensure that an appropriate fee is being paid by the transactions submitted to the network. By requiring gas (a transaction pay) for each operation it performs (or causes a contract to perform), we ensure that network doesn't become bogged down with performing a lot of intensive work that isn't valuable to anyone. This is a different strategy than the Bitcoin transaction fee, which is based only on the size in kilobytes of a transaction. Since Ethereum allows arbitrarily complex computer code to be run, a short length of code can actually result in a lot of computational work being done. So it's important to measure the work done directly instead of just choosing a fee based on the length of a transaction or contract.

How is GAS purchased/paid for?

As we have seen, gas is basically a transaction fee for the work done on the Ethereum blockchain. But then how do you pay it? This is where things get a little bit complex.

Although gas is a unit for measuring the work, there isn’t any actual token for gas. That is, you cannot just own 1000 gas. Instead, gas exists only inside the Ethereum Virtual Machine (EVM) as a count of how much work is done. When it comes to actually paying for gas, the transaction fee is charged as a certain number of Ether (the built-in token of Ethereum).

Gas as the unit of measurement

There is still a question that troubles us and this is; gas is paid for in Ether, why not have the operations charged directly in ether? The answer to that is that Ether has a market price that can change rapidly! But the cost of computations doesn’t go up or down with the change in ether price. Thus, it helps in maintaining the price of computations even when the price of ether may vary.

To make things more clear and understandable, let us examine this “GAS” in more detail. First, there are some basic terms you need to be familiar with to fully understand the concept.

Gas Price

Gas is paid for in Ether. It’s like getting gas for your car. You use the gas to run the car, but the amount that has to be paid for the gas is in Dollars. Every transaction specifies the Gas Price it is willing to pay in ether for each unit of gas, allowing the market to decide the relationship between the price of ether and the cost of computation. It is the combination of the two, total gas used multiplied by the gas price paid, that results in the total fee paid by the transaction. There is a difference between your transaction running out of gas and your transaction not having a high enough fee. If the gas price I set in my transaction is too low, no one will even bother to run my transaction in the first place. It will simply not be included in the blockchain by miners. But if I provide an acceptable gas price, and then my transaction results in so much computational work that the combined gas costs go past the amount I attached as a fee, that gas counts as "spent" and I don't get it back. The miner will stop processing the transaction, revert any changes it made, but still include it in the blockchain as a "failed transaction", collecting the fees for it. This may seem harsh, but when you realise that the real work for the miner was in performing the computation, you can see that they will never get those resources back either. So it's only fair that you pay them for the work they did, even though your badly designed transaction ran out of gas.

It is like the hourly wage being paid for the work to be done.

Gas cost

Gas cost is the units of gas consumed in one transaction or in general, in a single computation. It is the amount of work that goes into something, like the number of hours of labour.

Gas Limit
You can think of Gas limit as the amount of litres your car can have. In simpler way, the capacity of the fuel tank of your car, only in this case it is for blockchain.

Each operation on the EVM (Ethereum Virtual Machine) costs gas. For example, an Addition (ADD) consumes 3 gas. Here is a spreadsheet of Ethereum’s operations and their gas consumption.

Metering is different from fee and gas is different from ether. To help clarify this, consider the term “gas” synonymous with fuel. A transaction must provide enough fuel (startGas) to cover its entire use of the EVM’s computation and storage facilities. All remaining gas is refunded to the transaction’s originator: the user who initiated the transaction. A transaction that runs Out of Gas is reverted, but is still included in a block and the associated fee is paid to the miner.

With an overview from the perspective of fuel, let’s turn to an overview of fees. While every operation in the EVM consumes a predefined amount of gas that is fixed (for example, a MUL operation always consumes 5 gas), a user can specify a gas price in every transaction. The current gas price is 0.02µ Ethers, or 0.00000002 ETH. The fee an originator pays a miner is the transaction’s (startGas - remainingGas) × gas price.

Here is a summary of the influences of transaction fuel and transaction fee:
Screen-Shot-2018-04-11-at-10.22.42-AM
Image source: Stackexchange

At the start of a transaction, the Ether required for the startGas is set aside, and the remainingGas is set to startGas. With each operation of the transaction, gas is consumed and remainingGas is lowered. If there’s an Out of Gas exception, all operations are reverted and all the Ether that was initially set aside is given to the miner. If the transaction completes successfully, all the remainingGas is refunded to the originator and the rest is paid to the miner.

An example

In the following mock scenario, assume that a STORE consumes 45 gas and an ADD consumes 10 gas. The scenario involves storing the number 31 in the EVM, summing 2 numbers, and then storing the sum. Let’s assume that the originator specified a startGas of 150 and a gas price of 0.02µETH, Below is an illustration as the transaction is processed by the EVM:

The originator pays the miner a fee of (150 - 50) × 0.02µETH = 2µETH = 0.000002 ETH.

Note: the above example has been taken from stackexchange

How is the Gas price determined?

You determine the price of gas AND maximum amount of gas you want to spend on performing a transaction on the Ethereum network. Although gas limit is just a simple quantity, gas price is measured in ether (specifically some amount of wei, usually gwei). The value of gas is driven by the market and the nodes that prioritize higher gas prices when mining transactions. The current gas price can be seen on Etherscan or EthGasStation. As I mentioned, gas price is usually some amount of gwei. Wei is the smallest unit of ether, and gwei is simply 1000000000 wei.

Screen-Shot-2018-04-11-at-11.22.01-AM Screen-Shot-2018-04-11-at-1.42.35-PM

References: EthDocs, Stack exchange, Blockgeeks, MyEtherWallet, Wikipedia

____________________________________________________________________________________________________

Disclaimer: This is not an investment advice and should NOT be viewed as project endorsement by EtherWorld. Readers are suggested to do their research before investing into any project.

Follow us at Twitter, Facebook, Google+, Medium and Steemit.

____________________________________________________________________________________________________

Subscribe to EtherWorld.co