January 20, 2023

Gwei to ETH – How to Calculate and Convert Gwei to Ether

Table of Contents

Easily convert gwei to ETH or vice versa using our gwei to ether converter:

If you are interested in learning what gwei is and understanding the calculation behind the above converter, make sure to explore the upcoming sections. Or, start building dapps (decentralized applications) with the ultimate Web3 APIs from Moralis. For instance, you can use Moralis’ Token API to fetch token prices in gwei and automatically return the value in USD:

const response = await Moralis.EvmApi.token.getTokenPrice({

    address,

    chain,

});

To access the power of the above endpoint and many others, you just need a free Moralis account!  

Implement the gwei to ETH converter - Sign up with Moralis

Gwei to ETH – Overview

The above gwei to ether converter is a useful tool and can help you save a lot of time when dealing with gas prices or on-chain data. However, we believe it’s important you understand the concepts behind these units and their conversions. Therefore, we will first answer the “what is gwei?” question. Then, we’ll go over all ether denominations. Finally, we’ll focus on how to convert wei to gwei, wei to ETH, and gwei to ETH. 

As a bonus, we’ll also show you how to create a neat dapp (decentralized application) that utilizes the above-showcased “getTokenPriceToken API endpoint. This is also where you’ll get to meet Moralis and its core products. You’ll also learn how to obtain your Web3 API key in two simple steps. After all, the latter is the key to building dapps the easy way!  

Direction sign pointing at gwei and ether

What is Gwei?

Gwei is the most popular denomination of the Ethereum chain’s native currency: ether/ETH. If you’ve transferred any ETH in the past, you’ve probably encountered gwei as the unit for gas prices. After all, not long ago, the most popular Web3 wallet, MetaMask, displayed gas prices in gwei. However, currently, MetaMask focuses on displaying gas fees in ETH and US dollars. Though, you can still see the fees in gwei if you explore the “Advanced gas fee” options in MetaMask:

MetaMask module showing gwei to ether and USD calculations

Serving as units for gas prices made gwei the most popular denomination of ether. But “gwei” is not a random combination of letters. It is the result of merging “giga” and “wei”. If you remember your elementary or high school physics and math lessons, you may recall that “G” is an abbreviation for “giga”. Hence, “giga wei” becomes “gwei”. You may also remember that “giga” equals ten to the power of nine (109), but more on that in the “Ether Denominations” sections. Instead, let’s now focus on “what is wei?”. After all, this is the question you need to be able to answer if you want to fully understand “gwei”.

Hologram with the Ethereum symbol and ETH lettering

Wei is the atomic unit of ether – the smallest denomination of ETH. It is named after Wei Dai – a computer science graduate of the University of Washington. Wei Dai formerly worked as a cryptography researcher at Microsoft and was also a part of a cypherpunk movement in the 1990s. This makes Wei Dai one of the scientists who developed the theoretical underpinnings for cryptocurrencies. However, the main reason why wei (the unit) got named by Wei Dai is because of his innovation of “b-money”. He discussed this innovation in a self-published proto-crypto manifesto and, in turn, laid the foundation for smart contracts. 

Black background with a white math calculation - wei to ether

Ether Denominations

Now that you know what wei and gwei are, we are one step closer to diving into the gwei to ETH conversion. However, to properly understand the gwei to ether calculation, you should review all ether denominations:

  • The smallest denomination of ETH: wei
    • 1 wei = 0.000000000000000001 ETH = 10-18 ETH = 10-9 gwei
  • Thousand times larger (kilo – k) unit than wei: kwei, also known as “Babbage
    • 1 kwei = 1,000 wei = 0.000000000000001 ETH = 10-15 ETH = 10-6 gwei
  • Million times larger (mega – M) unit than wei: mwei, also known as Lovelace
    • 1 mwei = 1,000,000 wei = 0.000000000001 ETH = 10-12 ETH = 10-3 gwei
  • Billion times larger (giga – G) unit than wei: gwei, also known as Shannon
    • 1 gwei = 1,000,000,000 wei = 0.000000001 ETH = 10-9 ETH
  • Million times smaller (micro) unit than ETH or trillion times (tera – T) larger unit than wei: microether, or twei, also known as Szabo
    • 1 microether = 1 twei = 1,000,000,000,000 wei = 0.000001 ETH = 10-6 ETH = 103 gwei
  • Thousand times smaller (milli) unit than ETH or quadrillion times larger (peta – P) unit than wei: milliether, or pwei, also known as Finney
    • 1 milliether = 1 pwei = 1,000,000,000,000,000 wei = 0.001 ETH = 10-3 ETH = 106 gwei
  • Quintillion times larger unit than wei – the basic unit of Ethereum: ether (ETH), also known as “Buterin
    • 1 ETH =  1,000,000,000,000,000,000 Wei = 109 gwei

Here’s a recap of the above-listed wei and gwei to ether conversions:

Denominations of ether table showing values of gwei to ETH, etc.

How to Convert Wei to Gwei

One way to convert wei to gwei is to use a reliable converter, such as the one at the top of the article. However, as a developer, you may prefer to use a calculator or a spreadsheet, or even a line of code to convert wei to gwei. In that case, you can follow these two steps:

  1. Get the amount in wei
  2. Divide the amount in wei by 1 billion (109

Here are the above instruction written with a formula:

The amount in wei / 1,000,000,000 = The amount in gwei

Let’s look at an example where you are dealing with the amount of 370,590,000,000 wei. If we now use the above formula, we get the following: 

370,590,000,000 / 1,000,000,000 = 370.59 gwei

Often, you may also want to know the USD price of the amount in gwei. In that case, you need to know the current ETH value in USD and use the following equation:

The amount in gwei x the current price of ETH in USD / 1,000,000,000 = The price in terms of USD

If we apply the above formula to our example, we get this:

370.59 gwei x $1,580 / 1,000,000,000 = $0.0005855322

How to Convert Wei to ETH

When it comes to converting wei to ETH, things are relatively similar to the wei to gwei example. The only difference is that you must divide the value in wei with a larger number. So, the two steps when converting wei to ETH are:

  1. Get the amount in wei
  2. Divide the amount in wei by one quintillion (1018

This is the formula you need to convert an amount in wei to ETH:

The amount in wei / 1,000,000,000,000,000,000 = The amount in ETH

If we use the same amount in wei as in the above example, the “wei to ETH” formula looks as follows:

370,590,000,000 wei / 1,000,000,000,000,000,000 = 0.00000037059 ETH

To convert the above result into USD, we just need to multiply it by the current price of ETH:

0.00000037059 ETH x $1,580 =  $0.0005855322 

How to Convert Gwei to ETH

Now that you understand the wei to gwei and wei to ETH conversions, it should be quite straightforward to go from gwei to ETH. We know that one gwei is 0.000000001 ETH. So, the two steps for the gwei to ETH conversion include the following:

  1. Get the amount in gwei
  2. Multiply the amount in gwei by 0.000000001

However, since multiplying by 0.000000001 is the same as dividing by 1,000,000,000, the conversion from gwei to ether essentially follows the same path as wei to gwei. As such, the following formula takes care of converting gwei to ETH:

The amount in gwei / 1,000,000,000 = the amount in ETH

So, in the case of the amount of 370.59 gwei, the above formula converts into the following:

370.59 gwei / 1,000,000,000 = 0.00000037059 ETH

All these formulas can be quite handy when working with on-chain data, particularly cryptocurrency prices and gas fees. Yet, if you choose the right tools, you may not need to worry about different conversions. This is the case when using Moralis’ “getTokenPrice” endpoint. The latter returns the prices in wei and also in USD.

Moralis – Bridging the Development Gap Between Web2 and Web3

Unless you’ve been living under a rock, you know that Moralis is the ultimate Web3 API provider. Its enterprise-grade APIs enable you to query any on-chain data with single lines of code. The ever-expanding and improving fleet of Moralis’ products currently include:

Whenever you want to fetch on-chain data, the Web3 Data API allows you to do that efficiently and fast. With the Web3 Streams API, you can listen for real-time events on all leading blockchains. You can focus on smart contract events or wallet events and use them as triggers for your dapp activities, to trigger notifications, etc. With the Web3 Auth API, you can offer your dapp users various user-friendly options to enter the crypto realm. 

Thanks to Moralis’ cross-chain interoperability, you can use the above-listed APIs to build dapps on all leading blockchains. As a result, you are never stuck to any particular network, which future-proofs your work. After all, you get to target another chain by simply tweaking a single line of code. Of course, you can also target multiple chains at once to get a broader reach.

So, how do you get started with Moralis? Create your free Moralis account, obtain your Web3 API key, and use your legacy development skills to join the Web3 revolution. This is possible thanks to Moralis’ cross-platform interoperability, which supports the leading Web2 programming languages, frameworks, and dev platforms. Essentially, Moralis bridges the development gap between Web2 and Web3. In fact, make sure to take on the tutorial below and experience the power of Moralis firsthand. 

Documentation page of Moralis and how to get token price

Moralis and the Ultimate Token API

The above documentation page lets you test the power of the “getTokenPrice” endpoint for all supported chains. All you need is a token address you want to query. In fact, here are the lines of code in JavaScript:

import Moralis  from 'moralis';

import { EvmChain } from '@moralisweb3/evm-utils';

try {

    const chain = EvmChain.ETHEREUM;

    const address = 'token_contract_address';

    await Moralis.start({

        apiKey: 'YOUR_API_KEY',

        // ...and any other configuration

    });

    const response = await Moralis.EvmApi.token.getTokenPrice({

        address,

        chain,

    });

    console.log(response?.result);

} catch (e) {

    console.error(e);

}

To use the above lines of code, you need to replace “token_contract_address” with an actual ERC-20 token contract address and “YOUR_API_KEY” with your Web3 API key. You get to obtain your key in the following two steps once you have your free Moralis account ready: 

Web3 API landing page

Note: For a step-by-step tutorial on how to get the price of an ERC-20 token, visit the Moralis documentation.         

These are the results that the above script provides for Chainlink’s address – “0x514910771AF9Ca656af840dff83E8264EcF986CA”:

{

  "nativePrice": {

    "value": "4263234569532547",

    "decimals": 18,

    "name": "Ether",

    "symbol": "ETH"

  },

  "usdPrice": 6.709386191832593,

  "exchangeAddress": "0x1f98431c8ad98523631ae4a59f267346ea31f984",

  "exchangeName": "Uniswap v3"

}

Looking at the above results, you can see that the “getTokenPrice” endpoint returns the price in gwei (4263234569532547 gwei) but also in USD ($6.709386191832593). Using the above wei and gwei to ether conversion equations, you can easily calculate that the current ETH value in USD is $1573.778332.

We also encourage you to follow the video tutorial below and build a clean and simple dapp that allows you to get token prices in USD:

Gwei to ETH – How to Calculate and Convert Gwei to Ether – Summary

In today’s article, you learned how to calculate and convert gwei to ether. Along the way, we also explained what gwei and wei are. As such, you now know that the former is the basic unit for gas on the Ethereum chain, while the latter is the smallest denomination of ETH, named by computer scientist Wei Dai. We also looked at all major ether denominations, where you had a chance to refresh your high school knowledge. Aside from showing you how to convert gwei to ETH, we also explored equations for wei to gwei and wei to ETH conversions. Finally, you also learned the gist of Moralis’ superpowers and even found out that the “getTokenPrice” endpoint provides you with prices in gwei and USD. As such, it enables you not to worry about the gwei to ether conversion. 

If you enjoyed the above tutorial, we invite you to make the most of all Moralis resources. You can find many tutorials in Moralis’ docs and on the Moralis YouTube channel. However, if you are interested in learning more about different blockchain development topics, then Moralis’ blog is the place to be. Some of the latest topics cover the best Ethereum faucet, an ERC-721 vs ERC-1155 comparison, how to resolve any ENS domain, and much more. Of course, you can also take a more professional approach to your crypto education by enrolling in Moralis Academy. To better understand the leading programmable blockchain, we recommend starting with Ethereum fundamentals.    

Moralis Money
Stay ahead of the markets with real-time, on-chain data insights. Inform your trades with true market alpha!
Moralis Money
Related Articles
December 26, 2023

ETH Gas Tracker – Full Ethereum Gas Tracker Guide

November 16, 2022

Exploring AWS Lambda and What it is Used For

October 15, 2023

#1 API for Crypto Prices – Fastest Way to Get Prices of Crypto

March 6, 2023

Web3 Marketplace Development – Build a Web3 Business in 3 Steps

October 23, 2023

What is EIP-4844? All You Need to Know About Proto-Danksharding

March 15, 2023

ZK-Rollup Projects – Exploring Top ZK-Rollups in 2023

January 24, 2024

Understand Why Crypto is Up Or Down with a Crypto Price Movement API

October 20, 2022

How to Create a Decentralized Website on Ethereum

March 13, 2023

Buy ENS Domain – Where to Buy ETH Domains