简体   繁体   English

Solidity 中映射的替代方案? 或与另一个映射数据?

[英]Alternatives to mapping in Solidity? or map data with another?

I know that the question may sound strange but... are there alternatives for mapping in Solidity?我知道这个问题可能听起来很奇怪,但是......在 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.问题是,我必须知道谁有ERC721 ,就像一个dao ,“如果没有 Token,你就无法进入页面”,我的程序所做的是ERC721铸币功能令牌的 id 增加,以便每个人都可以拥有一个,因此使用id不可能知道谁拥有令牌,因为它会发生变化。 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 :)另外,忘了提到它不能用ERC1155完成:)

Thank you in advance🙃提前谢谢你🙃

The ERC721 standard defines a balanceOf(address) function that is supposed to return a number of tokens that the address owns. ERC721标准定义了一个balanceOf(address)函数,该函数应该返回地址拥有的许多令牌。

Example:例子:

  • address 0x123 currently owns tokens ID 1, 2, and 5地址0x123当前拥有令牌 ID 1、2 和 5

    • balanceOf(0x123) returns 3 balanceOf(0x123)返回3
  • address 0x456 has no tokens地址0x456没有令牌

    • balanceOf(0x456) returns 0 balanceOf(0x456)返回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.您可以将返回的值用作 Web 应用程序的授权方案,允许拥有至少一个集合的令牌(非特定,任何 ID)的用户登录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM