Solidity – How to Distinguish Fungible Token from Non-Fungible in ERC1155

blockchainerc-1155erc-721nftsolidity

How can I differentiate between a fungible and non-fungible token in ERC1155.

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

Is quantity of tokens is the only way?
What if I mint 10**18 amount of THORS_HAMMER, then how can I distinguish between other fungible tokens and this(THORS_HAMMER) non-fungible token?

Best Answer

You cannot.

The ERC-1155 specification does not distinguish between fungible and non-fungible tokens.

That means even if you receive a token that is a one-of-one, there is no guarantee at the ERC-1155 level that there will not be a second one of that same token and token ID.


If there are any additional guarantees available, then those are made at the implementation level.

Or in plain language:

Bob: how do you use shoes to fly?

Mary: shoes don't fly

Bob: well what about these shoes?

Mary: yeah, well those are flying shoe

Bob: so how do I fly with them?

Mary: it looks like there's a fly button right there on the side

Bob: does it work?

Mary: I don't know, why don't you try it?

Related Topic