在坚固性中随机选择铸造的NFT的最佳方法是什么?

发布于 2025-01-31 12:25:49 字数 455 浏览 3 评论 0原文

我想随机化不同级别的NFT铸造。如果总共有3333和20层(最好的),313 Tier 2、1200 Tier 3和1800 Tier 4,以下代码是否可以解决问题?这是否会导致每隔4个薄荷造成1级NFT?

function _genTier(uint256 seed) internal view returns (uint256) {
        uint256 index = seed % probabilities.length;
        uint256 rarity = seed.mul(100).div(MAX_SUPPLY);
        if(rarity < probabilities[index]) {
        rarity = index;
    } else {
        rarity = aliases[index];
    }

    return rarity;
}

I want to randomize how different levels of NFTs are minted. If there are 3333 in total and 20 Tier 1 (being the best), 313 Tier 2, 1200 Tier 3 and 1800 Tier 4, does the following code do the trick? Could this result in the Tier 1 NFTS being minted every other 4 mints?

function _genTier(uint256 seed) internal view returns (uint256) {
        uint256 index = seed % probabilities.length;
        uint256 rarity = seed.mul(100).div(MAX_SUPPLY);
        if(rarity < probabilities[index]) {
        rarity = index;
    } else {
        rarity = aliases[index];
    }

    return rarity;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

葮薆情 2025-02-07 12:25:49

TL; DR如果您已经在使用Oracle,则此方法将起作用。

您帖子中代码片段中的方法将导致稀有性,但是NFT不会随机分配,而是根据所提供的种子而按顺序分配。我不确定从哪里获得种子。

通常,我喜欢使用“随机盒子”技术,您可以在其中创建特质框,通过它们进行洗牌和循环。因此,您几乎会产生特质,最终以3333个项目的数组最终产生。如果您想保持确切的稀有性,

3333总共和20层1、313层2、1200层和1800层4

这是执行一代的好方法。相反,方法_gentier可能不会完全导致您提供的数字,只是造成每种NFT的可能性,如稀有性中所述。

但是,“随机框”方法对于坚固而言并不是最佳的,因为存储这大量数据所需的内存量将产生冗余成本,而这些成本可以通过使用随机性来避免。

另一方面,随机性也很难在链上获得。为了获取密码安全的随机数,您可以使用块哈希或甲骨文。

使用块哈希可能适用于此应用程序,但从其核心中可以预测。意思是,有人可以知道即将到来的哈希,并找出他们将要接收的NFT的层。

因此,我建议您研究

TL;DR if you are already using an oracle this approach is going to work.

The method from the code snippet in your post is going to result in the rarity, but the NFTs would not be assigned at random but in a sequence depending on the seed provided. I am not sure where the seed is obtained from.

Normally, I like to use the "random boxes" technique, where you can create traits boxes, shuffle and loop through them. So you pretty much generate the traits and end up with arrays of, in this case, 3333 items. If you would like to maintain exact rarity, like

3333 in total and 20 Tier 1, 313 Tier 2, 1200 Tier 3 and 1800 Tier 4

it is a good way to perform the generation. Conversely, the method _genTier might not lead to exactly the numbers you provided, just the likelihood of minting each of the NFTs being as outlined in the rarity.

However, the "random boxes" method is not optimal for Solidity as the amount of memory required for storing this much data would yield redundant costs which can be avoided by using randomness.

Randomness, on the other hand, is also difficult to obtain on-chain. To get the cryptographically secure random numbers you could use the block hash or an oracle.

Using the block hash might work for this application, but at its core it is predictable. Meaning, that someone could get the random number knowing the upcoming block hash and figure out the tier of the NFT they would be to receive.

Thus, I would advise looking into oracles like ChainLink to get truly cryptographically random numbers that cannot be predicted. The RNG from oracles comes from off-chain and conforms to the security standards. You could use the numbers and include an if-statement that would check the number of currently generated NFTs from each tier. Then, re-roll if say the 20 from the Tier 1 have already been allocated in order to ensure that the final 3333 is exactly as planned.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文