You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Polygon链ERC721合约部署异常:长时间未在Polygon Scan显示

问题:Polygon上部署ERC721合约后无法在Polygon Scan查询到,交易显示正在索引

部署ERC721标准NFT集合智能合约时,Hardhat执行部署命令无报错且返回合约地址,但数小时后在Polygon Scan查询该地址显示空白页面。其中一笔部署交易哈希为0xd78aaec758d1af0c0066f4dbea833a6a0e0730c18efe484545e5dfe1b5079a6f,状态显示正在被索引,不清楚原因及解决办法。

合约代码

pragma solidity ^0.8.4;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "hardhat/console.sol";

contract MintingThings is ERC721, ERC721Enumerable, Ownable {
    using Strings for uint256;

    string public baseURI;
    string private baseExtension;
    string public notRevealedTokenUri;
    //Override switches
    bool public paused = true;
    bool public revealed = true;
    bool public multipleMintsAllowedPerWallet = true;

    // check the max supply
    uint256 public maxSupply = 60; //adjust with image nmber

    event Minted(uint256 tokenId);

    constructor(
        string memory _name,
        string memory _symbol,
        string memory _initNotRevealedTokenUri,
        string memory _baseUri,
        string memory _baseExtension
    ) ERC721(_name, _symbol) {
        notRevealedTokenUri = _initNotRevealedTokenUri;
        baseURI = _baseUri;
        baseExtension = _baseExtension;
    }

    // internal
    function _baseURI() internal view virtual override returns (string memory) {
        return baseURI;
    }

    // internal
    function _notRevealedTokenUri()
        internal
        view
        virtual
        returns (string memory)
    {
        return notRevealedTokenUri;
    }

    // only owner.
    function mintTo(address to) external onlyOwner {
        uint256 supply = totalSupply();
        uint256 tokenId = supply + 1;
        bool alreadyMinted = balanceOf(to) > 0;

        require(!paused, "Minting not allowed");

        require(supply < maxSupply, "No more NFTs remaining");

        if (!multipleMintsAllowedPerWallet)
            require(!alreadyMinted, "wallet already have the nft");

        _safeMint(to, tokenId);
        emit Minted(tokenId);
    }

    function tokenURI(uint256 tokenId)
        public
        view
        virtual
        override
        returns (string memory)
    {
        require(_exists(tokenId), "tokenId provided doesn't exist");

        if (revealed == false) {
            return notRevealedTokenUri;
        }

        string memory currentBaseURI = _baseURI();
        return
            bytes(currentBaseURI).length > 0
                ? string(
                    abi.encodePacked(
                        currentBaseURI,
                        tokenId.toString(),
                        baseExtension
                    )
                )
                : "";
    }

    //only owner
    function toggleReveal() external onlyOwner {
        revealed = !revealed;
    }

    function setNotRevealedTokenURI(string memory _notRevealedTokenURI)
        external
        onlyOwner
    {
        notRevealedTokenUri = _notRevealedTokenURI;
    }

    function setBaseURI(string memory _newBaseURI) external onlyOwner {
        baseURI = _newBaseURI;
    }

    function setBaseExtension(string memory _newBaseExtension)
        external
        onlyOwner
    {
        baseExtension = _newBaseExtension;
    }

    function setPaused(bool _state) external onlyOwner {
        paused = _state;
    }

    function toggleAllowMultipleMintsPerWallet() external onlyOwner {
        multipleMintsAllowedPerWallet = !multipleMintsAllowedPerWallet;
    }

    function burnAll() public onlyOwner {
        uint256 currentSupply = totalSupply();
        for (uint256 i = 1; i <= currentSupply; i++) {
            _burn(i);
        }
    }

    function _beforeTokenTransfer(
        address from,
        address to,
        uint256 tokenId
    ) internal override(ERC721, ERC721Enumerable) {
        super._beforeTokenTransfer(from, to, tokenId);
    }

    function supportsInterface(bytes4 interfaceId)
        public
        view
        override(ERC721, ERC721Enumerable)
        returns (bool)
    {
        return super.supportsInterface(interfaceId);
    }

    function setMaxSupply(uint256 _maxSupply) public onlyOwner {
        maxSupply = _maxSupply;
    }
}

部署交易信息

Transaction hash: 0xd78aaec758d1af0c0066f4dbea833a6a0e0730c18efe484545e5dfe1b5079a6f
Contract deployed in block: 63683589
Contract deployed to: 0x6fb7CFC8ca9AA8A2e0903e4A4BC014C16668854c

可能原因及解决办法

  • Polygon Scan索引延迟:Polygon网络节点偶尔会出现索引滞后,尤其是在网络拥堵时段。可等待24小时内完成索引,或清除浏览器缓存后重新查询。
  • 未提交合约验证:部署成功后未在Polygon Scan提交合约验证,导致页面无法展示合约详情。可通过Hardhat的hardhat-verify插件完成验证:
    1. 确保hardhat.config.js中配置了Polygon网络的Polygon Scan API密钥
    2. 执行验证命令:npx hardhat verify --network polygon 0x6fb7CFC8ca9AA8A2e0903e4A4BC014C16668854c "NFT名称" "NFT符号" "未揭露URI" "基础URI" "文件扩展名"(替换为实际构造函数参数)
  • 交易未完全确认:检查交易哈希对应的区块状态,确认是否已成功上链。若交易处于pending状态,可能是gas价格设置不足,需重新部署并调整gas参数。
  • 合约部署隐性异常:Hardhat返回地址不代表合约逻辑完全正常,可在构造函数中添加console.log输出参数,重新部署后查看交易日志,确认合约初始化状态。
  • 区块浏览器节点同步问题:尝试使用其他Polygon区块浏览器查询合约地址,确认合约是否实际存在。

内容的提问来源于stack exchange,提问作者JGarnie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 18:55:55