After using ERC721 to develop some Collectable collections of NFTs, i'm trying to implement an ERC1155 smart contract to manage a game collection of elements.

First, the needs

In a simplified version of the game I need:

  • Characters: A collections of character, each one is unique and have their own metadata (Exactly what a ERC721 is able to do)
  • Coin: Classic Fungible token, with an amount by address.
  • Cards: Here is the trick. I have a collection of multiple cards (let's say 100 different cards), and every card have their own number of instance. (Example: 500 instances of each common card, and 10 instances of each legendary cards)

The ERC1155 contract

If I understand well, I have at least one non-fungible token (characters) and one fungible token (coins), I have to implement the ERC1155 standards. (Even if I don't understand is my Card Collection is fungible (multiple instance of a single card) or non-fungible (cards have rarities))

Following OpenZeppelin ERC1155 Documentation I did this:

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

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

contract GameItems is ERC1155Holder {
    uint256 public constant CHARACTER = 0;
    uint256 public constant CARD = 1;
    uint256 public constant COIN = 2;

    constructor() public ERC1155("https://game.example/api/item/{id}.json") {
        _mint(msg.sender, CHARACTER, 1, "");
        _mint(msg.sender, CARD, 10**5, "");
        _mint(msg.sender, COIN, 10**18, "");


Mint on Constructor

Firs of all, I don't understand why do I need to mint all the items on the constructor ? I cannot let the users mint Characters and Cards by their own (like ERC721 contract) ? And instead of defining how many do I want, use a maxSupply(uint256 tokenId) function ?

Fungible / Non-Fungible ?

I really not understand how do this work. The documentation say (for this the doc example):

Note that for our Game Items, Gold is a fungible token whilst Thor’s Hammer is a non-fungible token as we minted only one.

So Token are defined Fungible and Non-Fungible if they are only one ? But.. How can it be unique ?

In my point of view, Characters can be minted an unlimited number of time (and probably coin too, but only from the game not from external). So do I have to removed those 2 lines ?

Cards: a Non-Fungible Collections of Fungible cards ?

It's starting to confuse me a lots..

Multiple Collection?

Do I have to define a Token ID for every card I have on the game ? Something like:

uint256 public constant CARD_A = 1;
uint256 public constant CARD_B = 2;
uint256 public constant CARD_C = 2;
/* [...] */
uint256 public constant CARD_ZZ = 100;

And them consider as collections of different token ? But I want them to be mint randomly. Example, a user who will mint 5 cards, will receive 2 CARD_A + 2 CARD_H + 1 CARD_ZZ. This is the good way ?

Cards are ERC721 like?

If I predefined all the cards with their metadata (like a classic ERC721) I will be able to control them individually but identical cards (example 2 instances of CARD_A) will not be considered as Fungible (and regrouped on OpenSea for example)


Sorry for the mess of this thread but I think I need for help to put things back in the right place.. I'm also looking for resources, tutorial, course, whatever quality i'm taking.

Thank everybody

  • Typically, posts with multiple questions aren't helpful to the community as a whole. Could you post each question as an individual post? Thank you. Aug 9, 2022 at 11:48


Your Answer

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

Browse other questions tagged or ask your own question.