ERC721G:
‍THE GAS STANDARD

BACKGROUND

0xInuarashi, our developer, is a stickler for his programming habits. As a developer, he’d been taught not to use modules — or any lines of code, for that matter — that he didn’t fully understand. This philosophy not only helps him avoid unexpected vulnerabilities but also allows to him indulge his curiosity in understanding why or how things work. This whole perspective is what drives the second habit: in his natural enjoyment of building things, he always tries to create and innovate his own custom contracts for development work.

ERC721G is an innovative and creative take on the possibilities of an ERC721 contract. To push the NFT space forwards, and invent new and efficient methods of achieving results with significantly reduced gas costs.

FEATURES

  • Batch Minting — a gas-efficient method of minting
  • Batch Mint and Stake — a gas-efficient method of minting and staking, potentially 2 to 3 times more efficient than Batch Minting alone
  • Single-Contract Staking / Unstaking — a gas-efficient method of staking and unstaking an NFT
  • Keep track of Total Time Staked — a useful metric tracker for NFTs that can be implemented for holding and staking rewards down the line
  • Keep track of Last Transfer Time — a useful metric tracker for NFTs that can be used to encourage HODLing and reward users who held their NFTs for extensive periods of time

ERC721G implements these methods very efficiently, reducing all the above actions from requiring multiple contracts to implement, and costly gas, to a single contract, and saves up to 95% of the gas costs associated with each of the following functionalities through clever and creative programming.

ERC721G desires to bring additional utility and innovation to the NFT space that encourages creative programming as well as efficient, gas-saving practices for the growth of the space.

THE NUMBERS

Compared to the previous non-optimized NFT contracts of the past, both ERC721G and ERC721A perform exceptionally well at saving gas on mints.

ERC721G offers a large feature-set including staking and NFT staking metrics, while maintaining impressive gas performance in batch minting, while ERC721A is hyper-optimized to the level of YUL assembly.

For flexibility and features, there’s ERC721G. 
For hyper-optimization, there’s ERC721A.

MINTING GAS COSTS
TOKENS MINTED
NON-OPTIMIZED NFT
ERC721G
ERC721A

1 TOKEN

150,000

73,803

73,429

5 TOKENS

600,000

81,799

81,161

10 TOKENS

1,150,000

91,794

90,826

20 TOKENS

2,200,000

111,784

110,156

To highlight the added functionality of ERC721G, comparisons between an external staking function vs a built-in mint-and-stake function were also made.

Gas costs for mints have been omitted from this graph. Rather, these are the incremental gas on top of batch minting, compared with external staking implementations.

TOKENS 
MINTED
EXTERNAL STAKING
(STANDARD)
EXTERNAL STAKING
(OPTIMIZED)
ERC721G
MINT AND STAKE
PESSIMISTIC
GAS SAVINGS
ADDITIONAL GAS COSTS

1 TOKEN

510,000

318,000

51,000

7,319

85.6%

5 TOKENS

1,020,000

610,000

15,239

91.1%

10 TOKENS

51,000

25,139

92.1%

255,000

172,000

44,939

92.6%

20 TOKENS

The biggest savings from ERC721G’s use will come from utilizing and maximizing its built-in mint-and-stake function. This was made possible due to data packing and batch logic.

These savings are a representation of ERC721G’s objective of being the optimal contract with a large enough feature set to accommodate most NFT functionalities in the most optimal way possible.

BATCH MINTING

Batch Minting — a method popularized by Azuki with ERC721A, uses single storage writes to mint multiple NFTs. This is done through lookup tracing, where the smart contract returns the owner of a batch of NFTs based on logic that finds the correct pointer. By doing this, batch minting saves up to 90% or more gas when batch minting multiple NFTs.

ERC721G uses batch minting logic in the form of Mint Indexes, where data is stored and lookup traced to either the Initialized or Uninitialized states to find the source-of-truth. The source-of-truth acts as the pointer which the smart contract returns the token’s data, including the owner address and more.

By doing this, ERC721G saves up to 90% or more gas in batch minting multiple NFTs with competitive performance to the best NFT smart contracts in the space.

BATCH MINT AND STAKE

Batch Mint and Stake is an innovative feature of ERC721G — mint your NFT and stake it in one single transaction, and one single smart contract. This method of minting and staking can save up to 95% or more gas compared to traditional methods.

This is because ERC721G efficiently uses the same storage for storing the token’s data, such as owner, and pack it to store additional points of information. In this case — the timestamp of staking, as well as tracking the total time staked and last transfer.

By storing this set of data using a single storage slot, ERC721G saves 5 times the storage required compared to traditional methods. The token owner, last transfer, stake timestamp, total time staked, and staker address is stored within one storage instead — with staker address returned using a special proxied logic when returning the owner. This data is completely compliant to the aforementioned batch minting logic, and builds upon it.

SINGLE CONTRACT STAKING & UNSTAKING

Staking and Unstaking is implemented within the NFT contract itself, and able to be enabled or disabled in deployment easily. In addition to that, they are modules which can be built upon by developers. This means that custom logic can be built on top of ERC721G’s staking and unstaking logic by any developer.

These staking fuctionalities are built upon the storage system mentioned above, and implement optimized methods of staking and unstaking by altering the stakeTimestamp of the token. Only one storage is written to store the timestamp, and in an extremely efficient way.

Gangster All Star: Evolution NFTs will have an unactivated staking function built-in to the smart contract for future compatibility.

TRACKING TOTAL TIME STAKED

Tracking the total time staked of an NFT is a metric that measures how long an NFT has been staked for. This is useful in encouraging staking, as well as rewarding holders for accumulating staked times. Moonbirds — a popular and well-known NFT project, implements tracking of total time staked in its “nesting” logic which has proven to encourage holders to stake their NFTs and keep them off marketplaces.

ERC721G natively implements this in its staking logic and optimized data structure. Again — the same storage slot stores this data, resulting in incredibly efficient gas costs for these processes as shown in the graphs above. Total time staked accumulates on every unstake transaction.

ENCOURAGING HODLING

Each ERC721G NFT comes with a tracker which stores the time of last transfer of the NFT. Project owners can reward their biggest fans which hold their NFT for long periods of times through loyalty rewards and more. HODLing is encouraged by keeping track of the last transfer time, and makes holders proud of how long they have diamond handed their NFTs for.

ERC721G stores this data in the same optimized data structure it has for token data — essentially resulting in users able to store this data for practically free.

MODULARITY

ERC721G’s functions are built with modularity in mind — which allows developers to pick and choose which features they would like for their collection.

Don’t need staking features? The contract works perfectly without them implemented.

Need to add custom logic to staking? Simply override and inherit the staking function, and add your custom logic beforehand.

For the brave, you can even modify the built-in functions to your heart’s desire.

CONCLUSION

ERC721G aims to bring batch minting to the next level — by exploring what is possible within optimization constraints and introducing built-in staking functions and metrics for fractions of traditional gas cost.

It is the feature-rich alternative to the popular batch minting method — ERC721A, with comparable gas fees while offering a wider range of functionalities.

Both implementations are hugely beneficial in reducing the gas costs associated with minting NFTs for the NFT space, and we believe that both ERC721G and ERC721A will help push the space fowards — to a more gas-efficient future.

We are happy to contribute to the ever-growing space of NFTs and push forwards creative coding and innovation. By open-sourcing our smart contract to the public, we seek to inspire other developers to innovative and create their own smart contracts built upon ERC721G.

For a detailed technical writeup, check out our developer @0xInuarashi’s MEDIUM ARTICLE.