We just launched the presale mint for @grayboysdao.
The average mint tx fee was under 0.01 eth, and in many cases closer to 0.008 eth to mint 3 Gray boys in 1 tx.
This is a thread on the optimizations we did to achieve that.
1/
First off, any project that has high gas fees to mint and is not doing any special with on chain generation or on chain data is proooobably not gonna make it (lol).
Regardless, some of these optimization tips apply to pretty much every nft project so read thoroughly.
2/
The easiest optimization is not using ERC721Enumerable unless you need it.
Most "How-to" guides online for writing NFT projects use this, but it's not a requirement and most projects don't even utilize the extra functionality.
This reduces gas by ~70% PER TOKEN MINTED.
3/
Minimize iterative loops. Every bit of computation required during contract function execution requires gas.
"for" & "while" loops are often the biggest culprits for ballooning gas fees. Do not use these unless absolutely necessary.
4/
TRIM. THE. FAT.
Any mint function modifiers you're using, make absolutely sure that you actually need them.
Oftentimes this may be using something like Reentrency Guard for example as a precaution when it may not necessary depending on the surrounding context.
5/
Remove unnecessary libraries to further trim fat.
This could be things like SafeMath in later solidity compiler versions that implement it by default, or helper libraries that have unoptimized implementations or hidden loops that cause ballooning gas fees.
6/
Explicitly label your functions as "external" where possible. This will force function parameter storage to use calldata instead of memory, further optimizing gas fees.
7/
Optimizing data type usage.
uint should be used in place of strings WHEN POSSIBLE.
uint256 ironically takes less gas to store than a uint8
bytes should always be used over byte[]
If bytes length has a known maximum length, use the lowest length possible. bytes1 to bytes32
8/
More on loops.
DO NOT DO COMPLEX OPERATIONS IN LOOPS UNLESS ABSOLUTELY NECESSARY, PERIOD.
THEY ARE EXPENSIVE.
9/
There's more little things, but these tips are going to give you the biggest savings for the least amount of effort.
There's not really an excuse for a project having high gas fees if they're simply minting and not doing on-chain generation, or on-chain data.
Follow 4 more!
• • •
Missing some Tweet in this thread? You can try to
force a refresh