1.0.3 • Published 2 years ago

gwei-slim-nft-contracts v1.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Save on ⛽️ writing custom NFT contracts

ContractDeploy GWEI% of block size
OptimizedChildNFT501,0641.6%
ERC721Base1,614,6465.4%

Deploy your own on-chain metadata NFT contract for only ~500k gwei.

For most NFT projects, the base 80% of NFT code is unchanged from OpenZeppelin. A transparent factory pattern works well when the implementation used is identical between NFT contracts, but what about custom logic and overriding certain portions of standard behavior?

This proxy pattern uses a solidity fallback to call into OpenZeppelin contract code for any undefined functions. When your NFT contract code calls these functions, permission is granted since the contract itself is the caller.

[YourNft] => fallback [BaseNFT]

Any functions on ChildNFT override the default behavior of the standard Openzeppelin ERC721 code. To add logic before or after these functions, the standard _mint, _burn and main NFT functions can be accessed by using the base() getter. This logic is all in DelegatedLogic contract.

The standard base contract code is loaded in using the delegatecall() pattern.

A few common additional features for NFT series are included: 1. ERC2981 royalties 2. BaseURI and tokenID string generation for fixed-sized collections. 3. Syntax sugar has been added for calling openzeppelin standard _ private functions from the contract implementing DelegatedLogic itself.

The deployed base contract OpenZeppelin code can be used to be the underlying implementation for many, many NFT contracts.

Getting started

  1. Clone the example repository: https://github.com/iainnash/example-gwei-optimized-minting-contract
  2. Update the contract code with your custom NFT contract information
  3. Ensure base NFT contract address is set in hardhat.config.ts for your network
  4. hardhat deploy --network NETWORK --tags MY_CONTRACT replacing YOUR_CONTRACT with your contract and NETWORK with the desired network.

Current Deployments:

Example Contract Deployed

How do I get started?

  1. Clone this repo
  2. Update your desired ChildNFT class
  3. Delete all unused ChildNFT examples and deployments
  4. Add address to deployed base ERC721Base to hardhat.config.ts
  5. hardhat deploy --network rinkeby --tags ChildNFT

Features

Things you now can get for no additional gas when writing your own NFT contracts:

  1. 4x (!) lower deployment cost in gas
  2. ERC2981 built-in option to enable, more complex usages can override the reading function
  3. URI + ID functionality built-in, able to override and reset base URIs
  4. Ability to gate transfer, burn, mint, or disable certain functionality when needed
  5. totalSupply without full enumerable interface implementation
  6. More legible "special" functionality on top of base NFT contract for readers
  7. Ability to verify contracts and add custom comments functionality without being beholden to a factory contract's rules.

Gotchyas

  1. ABIs need to be combined manually or use both contract interfaces for typechain (working on a fix soon)
  2. Native ERC721 functions will be shown as a "Contract Proxy" on etherscan