0

I know that the question may sound strange but... are there alternatives for mapping in Solidity?

Let me explain...

The thing is, I have to know who has the ERC721, it's like a dao, "you can't enter to a page if you don't have the Token", what my program does is a mint function of the ERC721, the id of the token increases so that everyone can have one, so knowing who owns the token is not possible by using the id, since it changes. They told me that I could use mapping and map who minted, it worked! but not completely since I needed everyone to be able to see who has it (who is stored in the mapping), is there any other alternative for this? or you can use mapping but see all the stored data(users that own the token)?

Also, forgot to mention that it can't be done with ERC1155:)

Thank you in advance

Bernardo Olisan
  • 665
  • 7
  • 20
  • 1
    Im not sure i fully understand your question, once a NFT is minted, its ID is permanent, so what do you mean by "knowing who owns the token is not possible by using the id, since it changes"? Also there is no need for a mapping in this case, the ERC721 standard has a function called `ownerOf(ID) -> owner address` so you can use that function to see who minted each token, and you can keep track of how many NFTs have been minted in a counter variable, so just create another function that calls that function with every number from 0 to the counter value and returns an array of addresses. – MrFrenzoid Jun 08 '22 at 18:10

1 Answers1

0

The ERC721 standard defines a balanceOf(address) function that is supposed to return a number of tokens that the address owns.

Example:

  • address 0x123 currently owns tokens ID 1, 2, and 5

    • balanceOf(0x123) returns 3
  • address 0x456 has no tokens

    • balanceOf(0x456) returns 0

You can use the returned value as an authorization scheme for your web app, allowing login for users who own at least one token (non-specific, any ID) of the collection.

Petr Hejda
  • 40,554
  • 8
  • 72
  • 100