最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

blockchain - Why are the NFT images not visible? - Stack Overflow

programmeradmin0浏览0评论

I created a ERC721 type smart contract to mint 8 NFT's to the Polygon blockchain. The NFT images are stored on my own server (for this project I don't use IPFS). I also created the corresponding json folder and files.

Meanwhile, I compiled and deployed the contract on Polygon and minted the 8 NFT's, all via de Remix platform. All went well but (as in my previous attempts) the NFT images are never shown (not in Metamask after importing the contract address, not in Polygonscan, nor OpenSea).

Below is the smart contract code I have used:

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Strings.sol";

contract WatergunsV3 is ERC721URIStorage, Ownable {
    uint256 public currentTokenId;
    uint256 public constant MAX_SUPPLY = 8;
    string public baseTokenURI;

    event NFTMinted(address indexed recipient, uint256 tokenId, string tokenURI);

    constructor(string memory name, string memory symbol) ERC721(name, symbol) Ownable(msg.sender) {
        baseTokenURI = "/";
    }

    function mint(address recipient) external onlyOwner {
        require(recipient != address(0), "Recipient cannot be zero address");
        require(currentTokenId < MAX_SUPPLY, "Maximum supply reached");

        uint256 newTokenId = ++currentTokenId;
        _safeMint(recipient, newTokenId);

        string memory tokenURI = string(abi.encodePacked(baseTokenURI, Strings.toString(newTokenId), ".json"));
        _setTokenURI(newTokenId, tokenURI);

        emit NFTMinted(recipient, newTokenId, tokenURI);
    }

    function setBaseTokenURI(string memory newBaseURI) external onlyOwner {
        require(bytes(newBaseURI).length > 0, "Base URI cannot be empty");
        baseTokenURI = newBaseURI;
    }

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

    // Function to receive Ether. msg.data must be empty
    receive() external payable {}

    // Fallback function is called when msg.data is not empty
    fallback() external payable {}
}

Could someone chime in please?

I'm expecting the NFT images to show up in Metamask, OpenSea and other platforms. Now I just see a placeholder image.

发布评论

评论列表(0)

  1. 暂无评论