領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匹配,則將合約執行完成,否則丟棄。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM