Skip to content

Similar to the MAYC collection, allow users who hold an NFT from your original NFT Collection to burn an ERC-1155 NFT collection to claim an NFT from your new NFT Collection!

Notifications You must be signed in to change notification settings

Tay-space/burn1155-mint721

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Similar to the MAYC collection, allow users who hold an NFT from your original NFT Collection to burn an ERC-1155 NFT collection to claim an NFT from your new NFT Collection!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • CSS 37.3%
  • Solidity 25.6%
  • TypeScript 19.0%
  • JavaScript 18.1%