[NFT marketplace] general smart contract architecture question

We can separate the creation of the NFT from the selling/buying.
Let’s suppose the NFTs are already created.

I’m assuming you are very familiar with ASA, smart contract, local storage, global storage, opt-in, minimum balance, indexer, …
If not, please read in details all the Get Started section of Algorand Developer Docs - Algorand Developer Portal as this is quite advanced.

Now, there are two options for the marketplace:

  • a smart contract created for each NFT that need to be sold (as I understand https://developer.algorand.org/tutorials/creating-an-nftmarketplace/ is doing - but I did not check the details). In that case, you need to have a way to register these smart contracts to list them. One solution is to add a special note in the application creation and then have the marketplace use the indexer to get all the application creation transactions with this note. For security reason, it would then need to check the application code is the expected one.
  • a global smart contract. Currently (but this may change soon), the global storage of a smart contract is limited to 64 key/values. So to be able to have as many NFTs as possible you will most likely want to use the following trick:
    • For each NFT, create a fresh account A and fund it with minimum balance, opt in to the NFT, and then transfer the NFT
    • Then, make an opt-in application call to the smart contract from A and rekeying it to the application account. This will essentially give full control of the smart contract to A. Now the smart contract owns A and the NFT inside. Rekeying is explained there: Rekeying - Algorand Developer Portal

The advantage of the second solution is that you really have a single smart contract and you can easily list all the NFTs being sold by listing all the accounts opted in to the smart contract.

2 Likes