zoukankan      html  css  js  c++  java
  • 领ploot nft空投,看loot项目的随机数

    ploot合约地址:https://etherscan.io/address/0x03ea00b0619e19759ee7ba33e8eb8e914fbf52ea#readContract
    领取nft空投是通过claim()函数调用

    
        function claim() public nonReentrant {
            // _globalTokenId 是自增参数, 初始为16000。 下面这行代码限制了最多8000个nft。
            require(_globalTokenId < 24001, "Token ID invalid");
            uint256 times = _claimTimes[msg.sender];
            uint256 ddddAmount = IERC721(ddddToken).balanceOf(msg.sender);
            require (times < 1 || (ddddAmount >= 4000000e18 && times < 5) || (ddddAmount < 4000000e18 && ddddAmount >= 400000e18 && times < 3) ||  (ddddAmount < 400000e18 && ddddAmount >= 40000e18 && times < 2 ) , "invalid claim times");
           //  调用 _safeMint(_msgSender(), _globalTokenId);  来获取nft
            _safeMint(_msgSender(), _globalTokenId);
            _globalTokenId++;
            _claimTimes[msg.sender] = ++times;
        }
        
    
    

    _safeMint(_msgSender(), _globalTokenId) 会给msgsender分发nft,并设置tokenid,loot nft就tokenid不一样, 其他都差不多。

    loot nft最大的特点是不同的nft会有不同的装备,比如,weapon,head等等。 装备稀有度决定了该nft的稀有度。所以claim到装备更好的loot nft是参加这项目最关键的点。

    获取装备通过pluck函数获取,第一个参数是tokenId,这个参数决定了等获取什么样的装备,具体如下:

        function pluck(uint256 tokenId, string memory keyPrefix, string[] memory sourceArray) internal view returns (string memory) {
            //通过tokenid算出一个伪随机数,这个rand参数甚至都不是随机数,他就是根据tokenid算出来的,tokenid不变,则rand不变。所以说tokenid决定了装备。
            uint256 rand = random(string(abi.encodePacked(keyPrefix, toString(tokenId))));
            string memory output = sourceArray[rand % sourceArray.length];
            //求mod运算,
            uint256 greatness = rand % 21;
            if (greatness > 14) {
                output = string(abi.encodePacked(output, " ", suffixes[rand % suffixes.length]));
            }
            //稀有装备
            if (greatness >= 19) {
                string[2] memory name;
                name[0] = namePrefixes[rand % namePrefixes.length];
                name[1] = nameSuffixes[rand % nameSuffixes.length];
                if (greatness == 19) {
                    output = string(abi.encodePacked('"', name[0], ' ', name[1], '" ', output));
                } else {
                    output = string(abi.encodePacked('"', name[0], ' ', name[1], '" ', output, " +1"));
                }
            }
            return output;
        }
    

    所以装备完全取决于tokenid,所欲抢带有高级装备的nft思路:
    按照pluck函数的算法,遍历16000-24000,就可以算出那些greatness>=19的,由于loot合约没有提供_globalTokenId查询接口,需要编写一个智能合约。通过智能合约去claim,只要当claim到的nft tokenId匹配,则将合约执行完成,否则丢弃。

    --- --- --- --- From 小小leo 的博客 --- --- --- ---
  • 相关阅读:
    使用servicename连接Oracle数据库
    使用SID连接Oracle数据库
    使用xlrd模块
    【Project Euler 8】Largest product in a series
    Git使用帮助
    【Project Euler 1】Multiples of 3 and 5
    VSCode使用新体验
    导出牛顿引力形式为平方反比的两种方式
    NOIP2018游记
    即将退役声明
  • 原文地址:https://www.cnblogs.com/xiaoxiaoleo/p/15230234.html
Copyright © 2011-2022 走看看