0

I am developing a Dapp for NFT minting. In order to mint a new 2nd NFT, the user has to burn the 1st one that he owns. I know that our Dapp can prompt the user to burn the 1st NFT. And only after it's successful, it can prompt him/her to mint the 2nd NFT.

But it's there a way to improve the UX by prompting the user once only?

I tried to use smart contract B (for 2nd NFT) to call smart contract A (for 1st NFT)'s burn function. But in order to do that, user needs to "approve" contractB to contractA (i.e. authorize contractB to burn 1st NFT on user's behalf). And that results in prompting the user to perform this "approve" action. (prompting user twice in total).

Any suggestion? Thanks.

1 Answer 1

1

I think it's possible by taking advantage of the safeTransferFrom function.

The user can just transfer the old NFT this way to the new contract, triggering its onERC721Received function. You need only to write the burn and mint logic into it.

So, the only transaction the user needs to do is:

nft1.safeTransferFrom(userAddress, nft2Address, tokenId);

And you need to write this function in the nft2 contract:

function onERC721Received(address _operator, address _from, uint256 _tokenId, bytes _data) external returns(bytes4) {
    require(msg.sender == NFT1, "Can receive only NFT1");

    // burn the NFT received
    // (I'm not sure if your NFT1 has this function, if not you can send it to address(0) I guess) 
    IERC721(NFT1).burn(_tokenId);

    // mint the new one
    // (I'm using the same tokenId as the burned one, of course you choose appropriately)
    _safeMint(_from, _tokenId);

    // import @openzeppelin/contracts/token/ERC721/IERC721Receiver.sol
    return IERC721Receiver.onERC721Received.selector;
}
5
  • 1
    If the NFTs from NFT1 are going to be locked into NFT2's contract, there's actually no need to burn them. In any case, OpenSea will keep showing them under the collection even though it catches the transfer to address(0)
    – Mouradif
    May 19, 2023 at 12:12
  • @0xSanson does it mean user only need to interact with NFT1 contract? And in that case, who will be paying the GAS fee for NFT2 contract for the burning and minting actions? Thanks.
    – Edward Tam
    May 19, 2023 at 15:56
  • @EdwardTam Yes the user interacts only with NFT1. Minting and burning are part of the same transaction, so he will be paying gas for it. As Mouradiff said, you can skip burning if you're ok in keeping nft1 locked inside nft2.
    – 0xSanson
    May 19, 2023 at 16:16
  • @0xSanson 1 more question. How can i pass the info (e.g. URI, Loyalty fee,...) to NFT2's contract for minting the new NFT?
    – Edward Tam
    May 19, 2023 at 16:51
  • @EdwardTam Isn't enough to specify the baseURI etc.. during deployment? Or are you doing something different? In this case I suggest you open another question adding some details about the contracts
    – 0xSanson
    May 19, 2023 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.