URI of a ERC1155 token

I have created a ERC1155 contract and deployed it. (Code Below)

I have used to the setURI function to set the URI contract itself.

What function is used to set the URI of the actual tokens I mint from the contract?

Thank you!


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

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

contract MetaRoomsRoomPass is ERC1155, Ownable {
    constructor() ERC1155("") {}

    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);
    }
}

ERC1155 constructor uses it.

constructor(string memory uri_) {
    _setURI(uri_);
}
1 Like

As explained in our documentation, our base ERC1155 implementation returns the same URI for all token ids, relying on the {id} substitution mechanism described there.

If you want different URIs for each id, you need to extend the contract using inheritance and add the necessary variables and functions.