3

I'm working on a contract that will tokens from a different contract get burned to mint a 'new token'. I am just looking for a bit of guidance to make sure I don't run into any pitfalls.

The architecture is as follows:

  • contract1 - existing tokens

  • contract2 - new tokens

The mint method of contract2 will require that 'X' tokens from contract1 are burned. I have thought of two different wants to handle this, and I'm not sure if there are best practices or anything on this.

  1. Set approval on contract1 for each token to be burned, then call the burn method of contract1 from contract2 for each token.
  2. Implement an ERC721Reciever on contract2 and have the tokens sent to it, then call the burn method.

Is there reason why I should pick one method over another?

2 Answers 2

1

I think both are valid options. I'd say the first one is a bit more secure and less easy to screw up, because of these two issues in the second approach:

  1. Can you be sure that each token transfer triggers onERC721Received. There is also transferFrom in IERC721 which doesn't trigger that.

  2. Can you be sure that each token transfer to contract2 is meant to trigger your new minting functionality.

So the second option sounds straightforward and elegant, but it may prove treacherous. The first approach is a rather typical approach and is quite bullerproof.

1
  • That's exactly what I was thinking, but someone had put some seeds of doubt in my mind so I was wondering if I was missing something. Thanks for the insight! Nov 1, 2022 at 17:36
1

You might test the gas cost.. somehow I think that the first option is cheaper even if you're trigging 2 different transactions... since you have less transfers

Scenario1 - 10 token per 10 burnt --> 1 approval for all & 20 transfers

TX1.     SetAprovalForAll (this could be your contract2 and call the burn function from here)
Transfer 2. Contract2(as operator) --10TokenToBurn--> 0X00000
Transfer 3. Contract2 --10MintedToken--> UserWallet

Scenario2 - 1 token per 1 burnt --> total transfers 3

Transfer 1.  UserWallet --TokenToBurn--> Contract2
Transfer 2. Contract2 --TokenToBurn--> 0X00000
Transfer 3. Contract2 --MintedToken--> UserWallet

This can add up if you're burning more than 1 token per transaction

Scenario2v2 - 10 token per 10 burnt --> total transfers 30

Transfer 1.  UserWallet --10TokenToBurn--> Contract2
Transfer 2. Contract2 --10TokenToBurn--> 0X00000
Transfer 3. Contract2 --10MintedToken--> UserWallet
1
  • this all add up since ERC721 does not support batch transfers.. the best solution for all would be if you can add the function to burn and mint in contract1 but its probably already been deployed.. right? hah
    – Casareafer
    Nov 2, 2022 at 5:39

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.