1

I have create a very basic ERC1155 token from this tutorial:

https://docs.openzeppelin.com/contracts/3.x/erc1155

// contracts/GameItems.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

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

contract GameItems is ERC1155 {
    uint256 public constant GOLD = 0;
    uint256 public constant SILVER = 1;
    uint256 public constant THORS_HAMMER = 2;
    uint256 public constant SWORD = 3;
    uint256 public constant SHIELD = 4;

    constructor() public ERC1155("https://game.example/api/item/{id}.json") {
        _mint(msg.sender, GOLD, 10**18, "");
        _mint(msg.sender, SILVER, 10**27, "");
        _mint(msg.sender, THORS_HAMMER, 1, "");
        _mint(msg.sender, SWORD, 10**9, "");
        _mint(msg.sender, SHIELD, 10**9, "");
    }
}

As you can see, 5 tokens are created when the contract is deployed. Each of this 5 token is associated to a metadata file:

https://game.example/api/item/0000.....0001.json
https://game.example/api/item/0000.....0002.json
https://game.example/api/item/0000.....0003.json
https://game.example/api/item/0000.....0004.json
https://game.example/api/item/0000.....0005.json

I want to customize this 5 urls. They need to be very different. Is it possible ? I can override ERC1155 functions but i want to be compliant to ERC1155 in order to keep my token compatible with market places.

Thanks

1

Yes, you can make changes in the functions (e.g. changing the metadata URL), but you cannot change the number/types of input arguments nor return values, because this would violate the interface (see Function Overriding for more details).

Note that if you were inheriting from ERC1155Mintable, you could also call setURI to update your metadata URLs.

2
  • In your example setURI is an empty function (just contain an event emit...) – Bob5421 Apr 9 at 6:49
  • Yes, it's a minimal example. You would probably also add a _setURI call like in the ERC1155 constructor. If you just want to replace "game.example/api/item{id}.json" with something else, you can change it right there in the GameItems constructor argument (just make sure it contains {id}). – pwagner Apr 9 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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