NFT redemption code

I want to hand out at an in-person event a door prize for NFTs. Many people will not be familiar with crypto at all and this can be their entrance. It should be a piece of paper but could be a QR code or a redemption code but probably not longer than 16-20 characters. I want to create a Dapp where they can install a wallet, enter the code and become the owner of the NFT. I will also be glad to pay the gas so they do not need any eth right away.

I am fine with creating the ERC721 contract ( thanks openzepplin wizard ) but I think my Dapp should interact with another contract that does the transfer.

Has this been done ? Any pointers on how to make this secure ?

Thanks In Advance.

Welcome @allaboutnft!

You may be interested in our NFT Airdrops workshop to learn about some cryptographic tools you can use to build this.

Hey, I'm looking for something like the OP, earlier I looked into the video and tried some options from the workshop repo. I was thinking of using the merkle solution - but realised that I would have to use a backend service to provide the proof to the frontend, to not reveal other mint codes.

Is there a similar method where I wouldn't have to expose the access codes?

This is not a problem if the mint codes are hardcoded to specific accounts that can redeem them. Can you do that?

No, that's not an option - the point of the codes is that the addresses are not known. A solution I found was using https://github.com/a16z/zkp-merkle-airdrop-contracts, but that has a high gas cost.

How are mint codes distributed or assigned to people?

it can be physical or, digital treasure hunt

The solution you found in https://github.com/a16z/zkp-merkle-airdrop-contracts achieves more than what I think you want. The goal of that project is to try to anonimize users / avoid them doxing their own account. From your description I don't think that's what you're looking for.

Here's what I think you can do. You can publish the entire merkle tree publicly, where each leaf of the tree corresponds to a mint code. A mint code will contain a hash, and in order to redeem that mint code you have to present the preimage of that hash, along with the merkle proof. In this way the merkle proof on its own is not enough to redeem, and you can publish the merkle tree without revealing everything.

In your treasure hunt, the "treasures" would be the preimages, and you would have a dapp (or some other way) to generate the merkle proof for the corresponding mint code.

Something you need to be careful about is frontrunning. The simplest way to mitigate frontrunning is for users (or your dapp) to redeem using Flashbots RPC. This is not 100% safe but is an easy and cheap mitigation. The 100% safe way requires a commit-reveal scheme where users can first claim that they know a mint code preimage by submitting a hash of the preimage along with their address in a first transaction, and after a short while they can submit the mint code and proof in the clear to finally claim it.

1 Like

thanks interesting! Not sure how to publish the merkle tree publicly though without revealing the codes (in a no-backend setup), using merkletreejs: https://github.com/OpenZeppelin/workshops/blob/master/06-nft-merkle-drop/test/4-ERC721MerkleDrop.test.js#L20

The scheme I describe works without a backend. The mint codes are a hash, but they can't be redeemed without showing the preimage of that hash.

Thanks, I misunderstood that part in the workshop example! And as you described the claim + reveal scheme can prevent frontrunning. Thanks for the explanation!