<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by kaymo on Medium]]></title>
        <description><![CDATA[Stories by kaymo on Medium]]></description>
        <link>https://medium.com/@kaymo.eth?source=rss-c27d531a06ea------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*3xdEqRtvOtVvyDfX9ODdyg.jpeg</url>
            <title>Stories by kaymo on Medium</title>
            <link>https://medium.com/@kaymo.eth?source=rss-c27d531a06ea------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 04:06:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kaymo.eth/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to optimize Ethereum NFT smart-contracts to reduce gas usage for deployment and minting]]></title>
            <link>https://medium.com/@kaymo.eth/optimizing-nft-smart-contracts-to-reduce-gas-usage-7f4e819eb49d?source=rss-c27d531a06ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f4e819eb49d</guid>
            <category><![CDATA[nft]]></category>
            <category><![CDATA[smart-contract-blockchain]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <dc:creator><![CDATA[kaymo]]></dc:creator>
            <pubDate>Wed, 17 Nov 2021 02:32:43 GMT</pubDate>
            <atom:updated>2022-02-27T05:26:57.710Z</atom:updated>
            <content:encoded><![CDATA[<p>With the current state of the Ethereum network, developers are scrambling to find ways to minimize gas consumption of their decentralized applications. Even as a blockchain veteran, it can be hard to justify spending close to $100 on gas fees to complete a minting transaction. Below, I talk about two different methods which can help reduce the gas amounts used by both deployment and minting transactions for NFT smart-contracts on Ethereum.</p><p>Leading up to this, I have been doing research into various methods to reduce gas usage. Many issues which are causing high gas consumption involve situational smart-contract code, but there are also some methods for reducing gas usage that seem to be rarely talked about.</p><h3><strong>ERC721 + ERC721Enumerable vs ERC721</strong></h3><p>One culprit of increased gas consumption for NFTs on Ethereum is the ERC721Enumerable library. ERC721Enumerable is a library which is widely used and adds several conveniences to NFTs and allows them to be enumerated. This ultimately makes it easier to find tokens by their associated tokenID by adding some utility functions like totalSupply, tokenByIndex, and tokenOfOwnerByIndex.</p><p>For a typical ERC721 token smart-contract, the first mint made by each wallet will cost slightly more than all future mints from the same wallet. In juxtaposition, contracts that use ERC721Enumerable see the cost increase after the first mint, only decreasing slightly for a single transaction if it’s a new wallet that is minting.</p><p>Let’s look at these two implementations and compare their deployment costs as well as mint a few items to get an idea of how much of a difference there really is.</p><p>Below is an example of a very basic implementation of ERC721 using ERC721Enumerable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/957e006d05d04bc67e4b7557ae8361b6/href">https://medium.com/media/957e006d05d04bc67e4b7557ae8361b6/href</a></iframe><p>Now, let’s assign some values to this by testing these contracts out in remix. If you want to try this out while reading this article, you can go to <a href="https://remix.ethereum.org/">https://remix.ethereum.org</a> and add this contract and deploy it under the Javascript VM.</p><p>Below is the deployment cost as well as gas amounts for the first 3 mints from two separate wallets. I tried to keep this test simple for view-ability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*UtZl_Uw4IDQ4JqBuGQvwcg.png" /><figcaption>GWEI: 142; ETH Price: $4272.00 USD</figcaption></figure><p>As you can see, the first mint is significantly cheaper than all subsequent mints. Mints after that are around 45–50% more expensive than the very first one, only becoming slightly less expensive if it’s the very first mint for a particular wallet.</p><p>Now, let’s look at a the same contract using only ERC721 and instead using our own totalSupply uint16 variable to keep track of the supply.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e7bcf765fa851cd4a27e0813ed1a3823/href">https://medium.com/media/e7bcf765fa851cd4a27e0813ed1a3823/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*uaIx2otGi1KzQcuzUD2Liw.png" /><figcaption>GWEI: 142; ETH Price: $4272.00 USD</figcaption></figure><p>As you can see, the prices are drastically different from the first contract. Minting for the end user is over 50% cheaper after the first mint coming from each wallet! Isn’t that just crazy?</p><h3><strong>Using contract optimization to deployment costs</strong></h3><p>Optimizing contracts through the compiler is a sometimes overlooked but very useful feature. In Remix, you can find it in the Solidity Compiler tab. For other environments such as Truffle, you can edit your truffle.config with the settings on this page:<br><a href="https://trufflesuite.com/docs/truffle/reference/configuration#compiler-configuration">https://trufflesuite.com/docs/truffle/reference/configuration#compiler-configuration</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/592/1*mV6LzJAFzmHEJbWCNZ56lQ.png" /><figcaption>Settings for Optimizing Contract</figcaption></figure><blockquote>I should note here that as per the documentation, the amount of runs is meant to reflect the number of transactions the contract should run throughout its lifetime. However, I’ve found that even with runs set to 1, minting is still slightly cheaper than with the default settings. Feel free to test this yourself.</blockquote><p>Let’s look again at the same ERC721Enumerable contract from above and see how this effects the overall cost.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*M900oqn7u2xvbEe2QOedaA.png" /><figcaption>GWEI: 142; ETH Price: $4272.00 USD</figcaption></figure><blockquote>Comparatively, this deployment costs 46.1% less than the non-optimized deployment, while still offering minting at a lower price. This is a deployment cost reduction in USD from $2001.12 to $1076.92. Truly incredible!</blockquote><p>For the sake of completion, I ran the same test using the plain ERC721 contract from above as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*mkCqA4ocR4KGWvJb5Wa7mQ.png" /><figcaption>GWEI: 142; ETH Price: $4272.00 USD</figcaption></figure><blockquote>Here we are seeing a deployment cost reduction of around 46.2%, while the minting fees are lower as well. Impressive!</blockquote><p>I also ran the last two tests which used optimization through a localized blockchain. Each test consisted of 1,000 mints with each contract with both optimization off and on. The results were identical.</p><p>To conclude, there are many ways to reduce your gas consumption on Ethereum and these two methods only represent a few of them! Many other factors can influence your smart-contracts gas consumption, such as the complexity of your smart-contracts functions. If you’re trying to optimize, you can use these methods, but optimizing your code itself will have a large impact too. Good luck!</p><blockquote>My names kaymo! If you liked this guide, feel free to get in touch with me on Twitter or Discord. You can also check out my NFT project: <a href="https://metacatsnft.com/">MetaCats</a>, it’s a project I solo developed, including the pixel-cats!</blockquote><blockquote>I love talking about blockchain development, and I’m always open to meeting new folks to chat with about it.</blockquote><blockquote>Socials</blockquote><blockquote>Discord: kaymo.eth#0256<br>Twitter: <a href="https://www.twitter.com/metacatsNFT">@metacatsNFT</a><br>Webpage: <a href="https://metacatsnft.com/">https://metacatsNFT.com</a><br>Discord: <a href="https://discord.gg/e3nyt59Rpv">https://discord.gg/e3nyt59Rpv</a><br>Wallet: 0xD9B14Ae501F6Ec30409C0687e022E5841560a0c0</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f4e819eb49d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>