[SOLVED] Tokenuri is not showing on opensea

i deploy the erc 721 contract on bsc test net(0x5542bD28FD0D8c22D4AC7D51E62735Ac32d32374) The mint function is working but the metadata is not showing on opensea test net. for metadata and image i am using pinata, here is the link for metadata

https://gateway.pinata.cloud/ipfs/Qmcchbbm2R6CdiwsYbcoLPcY7PSi7yska9HzDCvK977mMU.

the steps i am following: deploy the token, enable public mint , setting the tokenUri.

code

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract Minter is ERC721, Ownable{

  string private baseTokenURI;
  uint256 public mintPrice;
    uint256 public totalSupply;
    uint256 public maxSupply;
    uint256 public maxPerWallet;
    bool public isPublicMintEnabled;
    
    address public withdrawWallet;
    mapping (address=> uint256) public walletMints;


    constructor()  payable ERC721("NFTTutorial", "NFT") {
  
        mintPrice= 1 ether;
        totalSupply = 0;
        maxSupply=14400;
        maxPerWallet= 25;
        withdrawWallet=0x658385eb2Abf80C76DEeF0d99491d41Fd7B638ff;
  }

      function setIspublicMintEnable( bool isPublicMintEnabled_) external onlyOwner{
        isPublicMintEnabled= isPublicMintEnabled_;

    }

      function mint(uint256 quantity_) public payable{
        require(isPublicMintEnabled,"minting not enabled");
        //require(msg.value== quantity_* mintPrice, " wrong mint value");
        require(totalSupply+quantity_<= maxSupply,"sold out");
        require(walletMints[msg.sender]+ quantity_<= maxPerWallet);

        for (uint256 i=0; i <quantity_; i++){
            uint256 newTokenId=totalSupply+1;
            totalSupply++;
            walletMints[msg.sender] = walletMints[msg.sender] + quantity_; 
            _safeMint(msg.sender, newTokenId);
        }
    }

   /// @dev Returns an URI for a given token ID
  function _baseURI() internal view virtual override returns (string memory) {
    return baseTokenURI;
  }

  /// @dev Sets the base token URI prefix.
  function setBaseTokenURI(string memory _baseTokenURI) public {
    baseTokenURI = _baseTokenURI;
  }


   function withdraw(address payable _to, uint _amount) public {
        _to.transfer(_amount);
    }
}

This is the token URI being returned for tokenId 1: https://gateway.pinata.cloud/ipfs/Qmcchbbm2R6CdiwsYbcoLPcY7PSi7yska9HzDCvK977mMU1 which is not valid.

Again, don’t worry about it showing on OpenSea until you’re sure that the token URI is valid first.

As mentioned previously in the other thread you made, you will need to reupload your metadata to a folder so it is accessible from something like https://gateway.pinata.cloud/ipfs/hash/1. You are still trying to use the same static metadata from last time with setBaseTokenURI - it won’t work. You need to go over the tutorial again, make sure to read each part.

As an example, with Pinata (if that’s what you used to upload to IPFS), I uploaded a folder of with a file called 1 that has that JSON metadata of yours in it. That IPFS link is https://gateway.pinata.cloud/ipfs/QmezuU5RUbUVAzT5fiR7BRaZHpDx6Rvzsz4F689nU1aR3E/1.

For your contract, I have set the base URI to https://gateway.pinata.cloud/ipfs/QmezuU5RUbUVAzT5fiR7BRaZHpDx6Rvzsz4F689nU1aR3E/ - using that makes it work on OpenSea. So you need to do something similar.

Steps:

  1. Upload metadata folder to IPFS with Pinata - create a folder with a file called 1 in it - edit this file with the metadata object
  2. Upload this folder
  3. Get IPFS link and make sure that metadata is accessible from https://gateway.pinata.cloud/ipfs/hashhere/1
  4. Call setBaseTokenURI with value of https://gateway.pinata.cloud/ipfs/hashhere/
  5. Refresh metadata on OpenSea page for NFT token 1
1 Like

is there 1 in the last? cause it shows invalid!

here is my link: as you told me to create a folder and have a file name 1 in it with the metadata. then i set the metadata . but it did not work!!

here u have 1 in the end? why?

is there 1 in the last?

What do you mean in the last? That link works. And it is working on OpenSea.

here u have 1 in the end? why?

Because that’s where the metadata for tokenId 1 (the only token that has been minted for your contract) needs to be.

https://gateway.pinata.cloud/ipfs/hashhere/ is the base URI that you set

https://gateway.pinata.cloud/ipfs/hashhere/1 is the link to the actual metadata for tokenId 1

Please go over the tutorial again - you need to understand the fundamentals first of what you’re doing.

please paste the link on the browser
https://gateway.pinata.cloud/ipfs/QmezuU5RUbUVAzT5fiR7BRaZHpDx6Rvzsz4F689nU1aR3E/1. is it said invalid?

please tell me what i am doing wrong:

i deploy the contract, i upload a folder that has file name 1.json. i enable the public minting, i set the token uri(https://gateway.pinata.cloud/ipfs/QmQS5wX7BZUW3oDB3RbRtxdVUrWLGQVBrqWHP4dc71BHCP/)
then i mint 1 nft, where i am doing wrong?

Your new contract is fine.

https://gateway.pinata.cloud/ipfs/QmQS5wX7BZUW3oDB3RbRtxdVUrWLGQVBrqWHP4dc71BHCP/

That 1.txt needs to be just 1 - rename it without the extension and then reupload the folder to IPFS. Then copy and paste the new IPFS link here.

new link
[https://gateway.pinata.cloud/ipfs/QmRhbJoqMTeF1gxTM39nasdRgKpddqtt9UjwB1mfyDBSbf/

Looks fine, now you need to set the base URI for your contract to

https://gateway.pinata.cloud/ipfs/QmRhbJoqMTeF1gxTM39nasdRgKpddqtt9UjwB1mfyDBSbf/
2 Likes

oh man, thanks. it worked.

Hey Alex, I think I have a similiar problem. I hope you can help me with this as well.

This is mid CID. I set my Base URI like

ifps://QmZjvgvzaW9YEbMWVQpQizpWk5sncicMQ6Wc3DLFYhn4Ng

https://gatewat.pinata.cloud/ipfs/https://bronze-voluntary-guanaco-31.mypinata.cloud/ipfs/QmZjvgvzaW9YEbMWVQpQizpWk5sncicMQ6Wc3DLFYhn4Ng/

and all three failed. I definitely miss something but I can’t get what it is.

1 Like