How to calculate Ethereum gas prices
The gas price is too damned high

How to calculate Ethereum gas prices

TL;DR: Minting 10,000 NFTs on Ethereum today costs about a million dollars.

You may have read reports that the cost of doing stuff on the Ethereum blockchain is very high these days.

But what is "very high"?

People complain about rent in the city, and yet a lot of people still choose to live in cities. We need some hard figures to know what's going on.

We have to calculate how high, without actually spending any of the Ethereum cryptocurrency ether (or ETH, or Ξ) to find out.

In this article I am going to walk you through the 'test' launching of a non-fungible token (ERC721) smart contract, and subsequently using up-to-data data from various websites to determine, to the dollar, how much it costs to mint and to transfer such tokens.

It's a contract wizard, there has to be a twist...

First let's navigate over to the OpenZeppelin contracts wizard for an ERC721.

OpenZeppelin is a group that provides a collection of template smart contracts, so you and I don't have to roll our own and make all the same coding errors and introduce bugs that open up security vulnerabilities.

It's the same principle as someone a few thousand years ago eating the wrong kind of fungus - their sacrifice means that we now know to avoid deadly webcap and destroying angel mushrooms (although you'd have thought the names would be a clue not to consume them).

No alt text provided for this image

With the contract wizard you can select the features that you want your contract to have. I've used the options on the left, and have selected a "mintable" kind of ERC721, with each token having an Id one bigger than the previous, and I've added the "enumerable" functionality so the contract can be queried to find out how many tokens have been minted, and how many tokens a given address holds (marked 1).

For the next step, there's a handy button on the contracts wizard: the "Open in Remix" button (marked 2).

This is the Remix

Remix is an online Solidity compiler with a whole load of whistles and bells attached. If you want to do some serious coding you need an Integrated Development Environment (IDE) and toolchain on your local machine, but for testing or playing around, Remix is brilliant.

No alt text provided for this image

In the top right pane, we can see our ERC721 contract code, the bottom right is the console, which tells us what is happening as we click buttons and do stuff, and on the right are ... well, those buttons that we click to do stuff.

And so we're going to check the "Enable optimization" checkbox (marked 1), and click the big blue "compile" button to start with (marked 2).

Not much seems to happen after you do that, but in the background the barely human-readable Solidity code has been converted into bytecode, which is completely human-unreadable but is understood by computers running the Ethereum blockchain.

Next, you need to click on the Ethereum-arrow button on the very left (marked 3), just above the icon of a bug.

There's an army to deploy

What we are now going to do, is deploy this contract that we compiled on a virtual copy of the Ethereum blockchain, and then we are going to submit a few transactions to this deployed virtual contract. This allows us to find the gas cost of the deployment, minting a token, and transferring a token. Except I'm going to leave calculating the cost of a transfer as an exercise for the reader.

And because all of this is taking place on a virtual copy of the Ethereum blockchain, it doesn't cost a penny.

  1. Make sure that you've selected the correct contract - it's going to be at the bottom of the dropdown list marked 1.
  2. Then click the orange "Deploy" button (marked 2):

No alt text provided for this image

Two things will happen - the console will show some activity (remember, the console is the pane at the bottom right), and our test contract will appear in the list of "Deployed Contracts".

If you click on the green check-mark in the console, just after "creation of Test pending", you get to see all the details of the deployment of our ERC721 contract, including ... dum dum dum ... the transaction cost in gas, marked in the image below:

No alt text provided for this image

We now have the gas usage for deploying our contract, namely 1585928, but let's gather information for minting before we leave Remix and run off to calculate the dollar cost.

Our test contract is listed at the bottom of the left pane, under a small heading labelled "Deployed contracts". Click on the > symbol, and it will rotate to point downwards, and all the functions that our contract has will be shown:

No alt text provided for this image


We can now mint a virtual NFT in our virtual contract. Paste an Ethereum address into the text field next to the orange safeMint button (here's one: 0xab5801a7d398351b8be11c439e05c5b3259aec9b - that's Vitalik Buterin's address), and then click the orange safeMint button.

Activity will take place in the console, another green check mark will appear, and you can once again click on that check mark and scroll down to see the gas usage.

I have done all of that in the animated image above to make things clear. And now we know that minting an NFT in our contract requires about 127495 gas.

So let's recap. We have determined the following -

Deploying an NFT contract: 1585928 gas

Minting a single NFT in that contract: 127495 gas

But we are not done yet.

It's a gas gas gas

If someone asked you, "How much does it cost to drive from Helsinki to Moscow?", they're not going to be happy with an answer like "Oh, about 20 liters of petrol", because cost is measured in money, not volume of combustible fluid.

And on Ethereum, in order to execute your transactions or deploy your contracts, you need to pay for gas. In the local currency, which is ethers, or ETH. And so we need to look up the gas price, which you can do here, at the Ethereum Gas Station. Another good link is the Etherscan gas tracker, just in case you need to cross-check.

No alt text provided for this image

What we are interested in is the Gas Price, listed in a pale gray color at the bottom of each of those three boxes. There are a few things you need to understand:

  • Gas prices are "offers" or "bids" to the miners in order to get your transaction processed and included on the blockchain. It's not like pulling up at the petrol pump, where there are fixed prices. And so, you can choose to pay a high price per gas unit in order to get your transaction handled quickly, or you can pick low price if you can wait. But if you choose a price that is too low, your transaction may never be included.
  • Gas prices are given in gwei. Most of you are probably wondering, "What the hell is a gwei?" - it's 0.000000001 ETH.

You can see that at this point in time, a reasonable gas price to pick is 103 gwei per gas unit.

And so we have a formula:

cost of transaction in ETH = gas required * gas price in gwei * 0.000000001

Using this with the gas amounts we determined above, we get:

ETH cost of deploying an NFT contract: 0.163350584 Ξ

ETH cost of minting a single NFT : 0.013131985 Ξ

Note that this is the ETH cost at this very moment, using a gas price of 103 gwei. Gas prices change dramatically over time, as the following chart from Y Charts shows:

No alt text provided for this image

As if to prove a point, between calculating the prices above and copying and saving this chart, the price has jumped from 103 on average, to 154. So I'll do the calculations again:

  • ETH cost of deploying an NFT contract: 0.244232912 Ξ
  • ETH cost of minting a single NFT : 0.01963423 Ξ

And this is the ETH cost now, using a gas price of 154 gwei. Who knows what it will be in five minutes...

If you're ever stuck with converting between wei, gwei and ether, you can use the Ethereum simple unit converter site to do the calculations for you.

Show me the money

Finally, we can work out in dollars what the cost of these two Ethereum transactions (deploying an ERC721 contract and minting a single NFT in that contract) are. You can just type "<amount> ETH in USD" in Google, or you can visit a place like Coinmarketcap's converter page.

Doing so we get the following:

  • US dollar cost of deploying an NFT contract: 1,125.06?$
  • US dollar cost of minting a single NFT : 90.42 $

To put that in context - imagine that you wanted to deploy a CryptoPunks style contract and mint ten thousand punks. The total cost would be: 905325.06$.

Let's put that in big letters:


Minting 10,000 NFTs on Ethereum today* costs about a million dollars.

* November 13th, 2021, at 12:43 EET.

And that's why people are moving out of the city that is the Ethereum mainnet, and into the countryside of Polygon, Binance, xDai, and other layer 2 blockchains.

About the author

Looking after baby twins is so much fun.

Keir Finlow-Bates?is a blockchain researcher, inventor, and author.

You can buy a copy of his book, “Move Over Brokers Here Comes The Blockchain” at?

https://mybook.to/moveover.

Further Reading

You may find some of the following other things that I’ve written or recorded of interest:

Ready Artist One!?: why the current art NFTs are less valuable than you would think.

Magical Internet Money?: a short piece on the collective delusion that drives abstract stores of value.

Keir on Blockchain?: my YouTube channel, where I explain complex blockchain concepts in simple yet accurate ways using analogies.

Gerardo Lemus

Data Science (Financial Industry / Blockchain-DeFI)

3 年

Keir Finlow-Bates do you know if there is a similar study for other tokens (e.g. BSC, Solana, etc) ? I tried the same exercise for Ether (but did not want to pay the fees) and Algorand - which cost about 0.01 algo to mint (or about GBP 0.01 at current rates) -- But while much cheaper, NFT secondary market in Algo is almost non-existent -- I am looking for the Goldilock's platform (maybe BSC ?) https://lamatuk.medium.com/letters-from-a-blockchain-agnostic-94e3f7cbd065

Brett H.

Return of Play?

3 年

Fantastic.

Guy Davies

Chief Marketing Officer at Naoris Protocol I Blockchain Research at Brixton Pound I Blockchain For Social Good

3 年

Thank you Keir Finlow-Bates another crystal clear description :)

Tyler Covington

Network Systems Operator

3 年

Alot. That is how much, this is why Polygon will be the hero for NFTs as gas fees are super cheap. Celo may have a good chance as well.

要查看或添加评论,请登录

Keir Finlow-Bates的更多文章

  • Liquid Momentum

    Liquid Momentum

    (Article 3 in a series on decentralized exchanges and memecoins) In the previous two articles, I looked at how…

    6 条评论
  • Stirring the Liquidity Pool

    Stirring the Liquidity Pool

    (Article 2 in a series on decentralized exchanges and memecoins) In my previous article, I described how even if a…

    11 条评论
  • Insufficient Liquidity

    Insufficient Liquidity

    Every adult knows that the claw machines at fairgrounds are rigged. The gripping strength of the claw is weakened for…

    28 条评论
  • What happens when Bitcoin's block subsidy runs out?

    What happens when Bitcoin's block subsidy runs out?

    Miners are an essential component of the Bitcoin blockchain?—?they package transactions into blocks and publish them…

    31 条评论
  • There are not going to be 21 million BTC

    There are not going to be 21 million BTC

    There are not going to be 21 million BTC. I confess, that was a social media "hook" to get you to read on.

    70 条评论
  • Why Quantum Computing will not Crack Blockchain Burner Addresses

    Why Quantum Computing will not Crack Blockchain Burner Addresses

    This article is sponsored by Resonance Security. There are ongoing concerns about the impact that quantum computing…

    41 条评论
  • The CHEQs Crypto-Quiz Answers

    The CHEQs Crypto-Quiz Answers

    Last week we set a crypto-quiz over at CHEQs to give people the chance to test their crypto-security knowledge. The…

    20 条评论
  • The three top reasons for bad computer security

    The three top reasons for bad computer security

    (This post is sponsored by Resonance Security) It should be clear by now to anyone who uses the Internet that there is…

    11 条评论
  • How not to promote your new blockchain

    How not to promote your new blockchain

    Over the years I've seen new (and not so new) chains vying for attention using the following techniques: paying…

    31 条评论
  • Interview with the CEO of Beta?Breakers

    Interview with the CEO of Beta?Breakers

    A while back, Charles from Resonance Security scheduled a meeting for me to talk to the CEO of Beta Breakers, Evan…

    3 条评论

社区洞察

其他会员也浏览了