Giter Club home page Giter Club logo

gwei-slim-erc721-contracts's Introduction

Save on ⛽️ writing custom NFT contracts

Contract Deploy GWEI % of block size
OptimizedChildNFT 501,064 1.6%
ERC721Base 1,614,646 5.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 this repository (will publish on NPM after further review)
  2. Choose a contract to start off in the /contracts/examples/ folder
  3. Update the deploy folder with your contract information
  4. Set base NFT contract address in hardhat.config.ts
  5. hardhat deploy --network NETWORK --tags MY_CONTRACT replacing YOUR_CONTRACT with your contract and NETWORK with the desired network.

What still needs to be done?

  1. Better testing and security review
  2. Deploy ERC721Base to mainnet and update address of deployment in this repo.

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. 3.5x (!) 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

gwei-slim-erc721-contracts's People

Contributors

dblodorn avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.