Giter VIP home page Giter VIP logo

burn1155-mint721's Introduction

Burn an ERC1155 to Mint an ERC721 NFT

Similar to the Mutant Ape Yacht Club collection, this template shows you how to:

  1. Build a simple ERC721A Drop Contract - Mimicking the original BAYC Collection
  2. Build an ERC1155 Contract - Mimicking the Serum NFT Collection
  3. Create an ERC721 Drop with restrictions on who can claim, based on their ownership of the two above collections.

If you want to build a burn an erc721 token to get another erc721 token, refer to the burn721 branch.

Using This Template

npx thirdweb create --template burn1155-mint721

Released Contracts

Risks

Yuga Labs, the creator of the BAYC collection created a snapshot of NFT owner addresses and used this as an allow-list for the MAYC drop.

This prevented users from "renting" or temporarily gaining access to a BAYC NFT in combination with a serum and claiming the MAYC NFT.

This template does not implement a similar method of preventing this behaviour.

Guide

Below, we'll outline the key aspects of the code.

Checking Balance Before Claiming

Before the claim function is run in the MAYC contract, the verifyClaim function logic must be true.

Here is where we ensure the claimer has sufficient balance of both the serum and the BAYC collection NFTs.

    function verifyClaim(address _claimer, uint256 _quantity)
        public
        view
        virtual
        override
    {
        // 1. Override the claim function to ensure a few things:
        // - They own an NFT from the BAYClone contract
        require(bayc.balanceOf(_claimer) >= _quantity, "You don't own enough BAYC NFTs");
        // - They own an NFT from the SerumClone contract
        require(serum.balanceOf(_claimer, 0) >= _quantity, "You don't own enough Serum NFTs");
    }

Burn To Claim

Before claiming from the MAYC contract, the _beforeTokenTransfers function is run.

In this function, we enforce the user burns a serum

    function claim(address _receiver, uint256 _quantity) public payable virtual override {
        // Use the rest of the inherited claim function logic
        super.claim(_receiver, _quantity);

        // Add our custom logic to burn the serum NFTs from the caller
        serum.burn(
            _receiver,
            0,
            _quantity
        );
    }

Providing Contract Approval to Burn

For the contract to be able to burn a wallet's NFTs, it needs explicit approval.

We achieve this in the application side when the user tries to claim a MAYC from the contract, by calling setApprovalForAll:

  async function mintMutantNft() {
    // Check the approval of the mayc contract to burn the user's serum tokens
    const hasApproval = await serumContract?.call(
      "isApprovedForAll",
      address,
      maycContract?.getAddress()
    );

    if (!hasApproval) {
      // Set approval
      const tx = await serumContract?.call(
        "setApprovalForAll",
        maycContract?.getAddress(),
        true
      );
    }

    const claimTx = await maycContract?.call("claim", address!, 1);
  }

Join our Discord!

For any questions, suggestions, join our discord at https://discord.gg/thirdweb.

burn1155-mint721's People

Contributors

avneesh0612 avatar jarrodwatts avatar kumaryash90 avatar eabdelmoneim 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.