Note

If you are new to the blockchain technology, taking our Introduction to Blockchain Technology self-paced course is highly recommended. Also, for a comprehensive coverage of blockchain development in Ethereum or mastering Solidity programming, taking our below self paced courses is highly recommended:

Recap

In our previous article (How Smart Contracts Work in Ethereum), we learn how blockchain smart contracts work in Ethereum.

In this article, we discuss how Ether and Gas are used in Ethereum.

Ether and gas

The Bitcoin network uses Bitcoin as the cryptocurrency to bootstrap the network and has a sophisticated algorithm to control the coin supply. The miner, by providing computing capacity for costly mining processes, gets rewarded with new-minted coins and transaction fees in Bitcoin.
Ether is the cryptocurrency powering the Ethereum blockchain network. ETH is the officially listed symbol for ether. Gas is the energy fueling smart contract execution in EVM and can be purchased with ether. To obtain ether, you either need to trade for ether from the crypto market or sign up as the miner. In Ethereum, the supply side will be lowered with the move to PoS, simply because there is no expensive mining anymore that we need to compensate for. Ether will be issued at a constant linear rate during the block mining process. Interested readers can check out online discussions and blogs here, http://ethdocs.org/en/latest/ether.html, for more information about the pros and cons of supply limitations.
Wei is the smallest denomination of ether in Ethereum. One ether is one quintillion
or 1018 weis. The following table is a list of the named denominations and their value in wei:

Unit

Wei Value Wei
wei 1 wei 1
Kwei (babbage) 103 wei 1,000
Mwei (lovelace) 106 wei 1,000,000
Gwei (shannon) 109 wei 1,000,000,000
microether (szabo) 1012 wei 1,000,000,000,000
milliether (finney) 1015 wei 1,000,000,000,000,000
ether 1018 wei 1,000,000,000,000,000,000

Ethereum is a general-purpose decentralized computing platform powered by ether. In addition to mining, all Ethereum nodes need to perform all computational steps as defined in the smart contract as part of the transaction and block verification process. The Ethereum protocol charges a fee per computational step in exchange for the computing resources supplied by the network nodes for the contract execution.
The execution fee is dynamically determined based on the total gas needed for the execution, and the gas price within the network. Gas in Ethereum is an internal virtual machine token to identify relative cost between operations (calculations, storage, and memory access) of contract execution. The gas price per ether is determined by the miners and generally fluctuates as a result of supply and demand on the network. The sender can purchase the gas from the miners using ether. The sender creating a transaction needs to set both a gas limit and price per gas-unit, which together becomes the price in ether that is paid.

 

One-to-One Live Blockchain Classes

Coding Bootcamps school offers One-to-One Live Blockchain Classes for Beginners.

 

When a smart contract is compiled into bytecode, it is actually assembled as encoded opcode and loaded into the EVM. Each opcode is identified as specific operations. The total gas cost of those operations will be the cost of your transaction. Every time the sender sends a transaction to a contract, the following two inputs need to be provided:

  • gas: The gas limit the sender allows for processing a transaction
  • gasPrice: The unit gas price the sender is willing to pay

The execution fee the sender offers for the transaction will be calculated as follows:

gas * gasPrice (in eth/g) = ether

It is recommended to set a large enough gas limit since all unused gas is returned to the sender. If there is not enough gas, the miner still collects the fee even though the transaction execution will be rolled back. In the next article about the EVM, we will talk more about these computational steps and the gas associated with each step.

 

Next Article

In our next article (How Ethereum Virtual Machine works), we discuss how Ethereum Virtual Machine works.

 

This article is written in collaboration with Brian Wu who is a leading author of “Learn Ethereum: Build your own decentralized applications with Ethereum and smart contracts” book. He has written 7 books on blockchain development.

Resources

Free Webinars on Blockchain

Here is the list of our free webinars that are highly recommended:

 

Free Courses

Here is the list of our 10 free self-paced courses that are highly recommended:

 

Self-Paced Blockchain Courses

If you like to learn more about Hyperledger Fabric, Hyperledger Sawtooth, Ethereum or Corda, taking the following self-paced classes is highly recommended:

  1. Intro to Blockchain Technology
  2. Blockchain Management in Hyperledger for System Admins
  3. Hyperledger Fabric for Developers
  4. Intro to Blockchain Cybersecurity
  5. Learn Solidity Programming by Examples
  6. Introduction to Ethereum Blockchain Development
  7. Learn Blockchain Dev with Corda R3
  8. Intro to Hyperledger Sawtooth for System Admins

 

Live Blockchain Courses

If you want to master Hyperledger Fabric, Ethereum or Corda, taking the following live classes is highly recommended:

 

Articles and Tutorials on Blockchain Technology

If you like to learn more about blockchain technology and how it works, reading the following articles is highly recommended:

 

Articles and Tutorials on Ethereum and Solidity

If you like to learn more about blockchain development in Ethereum with Solidity, reading the following articles and tutorials is highly recommended:

 

Articles and Tutorials on Hyperledger Family

If you like to learn more about blockchain development with Hyperledger, reading the following articles and tutorials is highly recommended:

 

Articles and Tutorials on R3 Corda

If you like to learn more about blockchain development on Corda , reading the following articles and tutorials is highly recommended:

 

Articles and Tutorials on Other Blockchain Platforms

If you like to learn more about blockchain development in other platforms, reading the following articles and tutorials is highly recommended: