0

I have deployed a basic ERC1155 importing the Openzeppelin libraries.

Here is my smart contract.

// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";

contract MyToken is ERC1155 {
    address public platformOwner;

    modifier onlyOwner() {
        require(msg.sender == platformOwner, "Not an owner");
        _;
    }

    constructor()
        ERC1155(
            "https://beige-top-pelican-586.mypinata.cloud/ipfs/QmQP6RzFRCqm8PeJoZSPgM8mohyAgrtuWdy2ZqyAcKUNtx/{id}.json"
        )
    {
        platformOwner = msg.sender;
    }

    function setURI(string memory newuri) public onlyOwner {
        _setURI(newuri);
    }

    function mint(
        address account,
        uint256 id,
        uint256 amount,
        bytes memory data
    ) public onlyOwner {
        _mint(account, id, amount, data);
    }

    function mintBatch(
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) public onlyOwner {
        _mintBatch(to, ids, amounts, data);
    }
}

And, here is the metadata json file :

{
    "name": "Sun Heavens",
    "description": "Lorem ipsum...",
    "image": "https://lufinadevtest.oss-ap-south-1.aliyuncs.com/1715515909885-ss.png",
    "properties": {
        "simple_property": "example value",
        "rich_property": {
            "name": "Name",
            "value": "123",
            "display_value": "123 Example Value",
            "class": "emphasis",
            "css": {
                "color": "#ffffff",
                "font-weight": "bold",
                "text-decoration": "underline"
            }
        },
        "array_property": {
            "name": "Name",
            "value": [
                1,
                2,
                3,
                4
            ],
            "class": "emphasis"
        }
    }
}

Please have a look at this ERC1155 smart contract NFT, it's name and image is visible on Etherscan.

So, I want make visible my ERC1155 NFT same like above.

Please provide me some reference or solution for it.

Let me know if anything else is required from my side.

I have taken the metadata format from here -> https://eips.ethereum.org/EIPS/eip-1155

New contributor
Shiv Sharma is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

1 Answer 1

0

Any block explorer or OpenSea does not support this URI format:

https://beige-top-pelican-586.mypinata.cloud/ipfs/QmQP6RzFRCqm8PeJoZSPgM8mohyAgrtuWdy2ZqyAcKUNtx/{id}.json

So, you need to override the URI function to return the file name as a string:

function uri(uint256 _tokenid) override public pure returns (string memory) {
    return string(
        abi.encodePacked(
            "https://beige-top-pelican-586.mypinata.cloud/ipfs/QmQP6RzFRCqm8PeJoZSPgM8mohyAgrtuWdy2ZqyAcKUNtx/",
            Strings.toString(_tokenid),".json"
        )
    );
}

Here's the revised contract code:

// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/utils/Strings.sol";

contract MyToken is ERC1155 {
    address public platformOwner;

    modifier onlyOwner() {
        require(msg.sender == platformOwner, "Not an owner");
        _;
    }

    constructor()
        ERC1155(
            "https://beige-top-pelican-586.mypinata.cloud/ipfs/QmQP6RzFRCqm8PeJoZSPgM8mohyAgrtuWdy2ZqyAcKUNtx/{id}.json"
        )
    {
        platformOwner = msg.sender;
    }

    function setURI(string memory newuri) public onlyOwner {
        _setURI(newuri);
    }

    function mint(
        address account,
        uint256 id,
        uint256 amount,
        bytes memory data
    ) public onlyOwner {
        _mint(account, id, amount, data);
    }

    function mintBatch(
        address to,
        uint256[] memory ids,
        uint256[] memory amounts,
        bytes memory data
    ) public onlyOwner {
        _mintBatch(to, ids, amounts, data);
    }

    function uri(uint256 _tokenid) override public pure returns (string memory) {
        return string(
            abi.encodePacked(
                "https://beige-top-pelican-586.mypinata.cloud/ipfs/QmQP6RzFRCqm8PeJoZSPgM8mohyAgrtuWdy2ZqyAcKUNtx/",
                Strings.toString(_tokenid),".json"
            )
        );
    }
}

Here are the examples of the resultant minted NFT on different networks:

Note: Only Snowtrace explorer of Avalanche-Fuji is showing the metadata and image of the NFT, rest of the explorers like Etherscan and Polygonscan are only showing the quantity.

Here's the snowtrace explorer url of the above NFT (i.e., minted on Avalanche-Fuji): https://testnet.snowtrace.io/nft/0x6F52E6b1e5c16b46e55E58f42322845D20021BC2/1?chainId=43113

I think Etherscan explorer would show the image and metadata only when NFT is minted on mainnet as of now.

8
  • Hi @syed-asad-kazmi I have a production contract example as well, they followed the same override uri method flow, still they are not getting it (image & name). Smart Contract May 15 at 15:29
  • @ShivSharma, yeah same problem I’ve faced on Polygonscan mainnet as well. Can you try deploying and minting on Etherscan mainnet? Hopefully, it’ll display the image and metadata there. May 15 at 17:02
  • Hi @syed-asad-kazmi, I have tried in the oklink explorer (polygon mainnet), they are supporting the image, but still name is not visible. Sample ERC1155 token May 16 at 12:07
  • @ShivSharma, yeah same thing on my end as well: oklink.com/polygon/assets/… May 16 at 13:48
  • Yes it is visible, Thank you @@syed-asad-kazmi for your imp inputs. Let me know if we can do any code or json data change for name as well. So name of the nft also be visible May 16 at 14:43

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.