-1

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 = "https://13.39.73.207/json/";
    }

    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.

4
  • 1
    Opensea and other tools might ignore the URLs because you're currently using self-signed SSL certificate. I haven't found anything related in the docs and did not verify - so I'm only posting a comment and not an answer. But from my experience, many tools don't process self-signed URLs. Commented Feb 5 at 20:01
  • Thanks for that heads-up, I keep that in mind 👍🏻 Commented Feb 5 at 21:39
  • 1
    You're right. Problem solved, partially thanks to you. 1) Syntax error in smart contract (concatenating the base Uri twice). 2) Lacked certificate and domain linked to my server's IP. Don't use self-signed but use certbot (Let's Encrypt) certificate. Commented Feb 6 at 15:07
  • I'm glad to hear that. Feel free to post it as answer and mark the question as solved, so that others who search for similar problem can find the solution more easily. Commented Feb 6 at 16:00

1 Answer 1

0

Solved thanks to:

The problem is finally solved. Partially thanks to @petr-hejda: my self-signed certificate didn't do the trick. I had to link a domain to my IP and use certbot for a decent certificate.

The other issue was concatenating the base Uri twice inside my mint function. Corrected syntax: string memory tokenURI = string(abi.encodePacked(Strings.toString(newTokenId), ".json"));

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.