1

Is there a way to use the {id} substitution in ERC-1155 with IPFS storage? I'd like to host the metadata on ipfs and have the uri function return a link to it. A working example would be really helpful. Thanks!

1
  • I also need the answer to this.😭 Were you by any chance able to figure it out?
    – Adrian D.
    Aug 18, 2021 at 5:00

1 Answer 1

0

Although I am not sure what feature you are building, however if we are talking about id substitution for the uploaded NFT on IPFS you can follow the below steps:

Note: Pinata is used as the IPFS storage.

  1. Add your NFTs in a folder and upload that folder to an IPFS storage. After the folder is uploaded you will get a CID like QMsereiono8932ebhbfdflnelwfne. You can see the image using the following URL. For example, I have uploaded 1.png, I will be able to check it out using the following: https://ipfs.io/ipfs/QMsereiono8932ebhbfdflnelwfne/1.png

  2. Create metadata for all the uploaded NFTs and add their URL in the image key. Your metadata should have name, image, description and attributes keys. Here is a sample metadata. Make sure the name of the metadata file should be an integer like 1.json, 2.json and so on

     {
               "attributes": [{ "trait_type": "Color", "value": "Red" }],
               "description": "Sample Description",
               "image": "https://ipfs.io/ipfs/QMsereiono8932ebhbfdflnelwfne/1.png",
               "name": "Sample",
               "external_url": "https://ethereum.stackexchange.com/"
     }
    
  3. Add your metadata in a folder and upload that folder to an IPFS storage. After the folder is uploaded you will get a CID like Qiuewrbiw3223nncewocnnciuenw. You can see the metadata using the following URL. For example, I have uploaded 1.json, I will be able to check it out using the following: https://ipfs.io/ipfs/Qiuewrbiw3223nncewocnnciuenw/1.json

  4. Override the URI method of the ERC1155 contract as Opensea reads the metadata by calling that method. You need to import the following String utility functions from openzeppelin.

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

    function uri(uint256 _tokenId) override public pure returns (string memory) { return string(abi.encodePacked( "https://ipfs.io/ipfs/Qiuewrbiw3223nncewocnnciuenw/", Strings.toString(_tokenId), ".json")); }

That's it. Now you will be able to see you minted NFTs on the Opensea. Hope this helps.

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.