How is ERC-1155 NFT ID defined?

In Openzeppelin, how does ERC-1155 NFT id been defined as the standard does not mandate how an implementation must do this.

Shall I follow the split ID bits mentioned by EIP?

uint256 baseTokenNFT = 12345 << 128;
uint128 indexNFT = 50;

uint256 baseTokenFT = 54321 << 128;

balanceOf(baseTokenNFT, msg.sender); // Get balance of the base token for non-fungible set 12345 (this MAY be used to get balance of the user for all of this token set if the implementation wishes as a convenience).
balanceOf(baseTokenNFT + indexNFT, msg.sender); // Get balance of the token at index 50 for non-fungible set 12345 (should be 1 if user owns the individual non-fungible token or 0 if they do not).
balanceOf(baseTokenFT, msg.sender); // Get balance of the fungible base token 54321.
1 Like

Hi @SamT,

It really depends on your use case and how you want to implement it.

I haven’t experimented with the split ID approach.

In the simple examples I have experimented with I have used:

A fungible token in ERC1155 has a quantity greater than one.
A non-fungible token in ERC1155 has a quantity of one.

If you want a fungible token, mint multiples of them. In the example below Silver, Gold, Silver, Swords and Shields are fungible, whilst Thors Hammer (as only one is minted) would be non-fungible.

GameItems.sol

From: https://docs.openzeppelin.com/contracts/3.x/erc1155#constructing_an_erc1155_token_contract

// 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/{1}.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, "");
    }
}

Hi @SamT,

Checking in to see if you had any questions on this?

It seems like the specification doesn’t define the NFT strictly. So I would try to set the MSB as a flag of NFT/FT.
Thanks for your explanation.

1 Like

Hi @SamT,

The EIP leaves it open, so the choice is yours on how to implement.

Hello! I have some problem. I need to implement token index (or serial number) for each copy of token. Are you find solution?

Hi @SamT If thors hammer is created as nft and has token_id as 2, how can I create a fungible thor token now with same token_id?

Hi, Anup
If you minted Thors Hammer as a non-fungible token [quantity = 1], I don't think there's a way to change it to a fungible token, let alone one with the same Id.
One thing you can do is fractionalize the same NFT by wrapping it up with an ERC20 token. But that's a different domain and not the answer you're seeking for in my guess.