ERC1155 support on Etherscan and minting fungible and non-fungible tokens

:computer: Environment

:memo:Details

:1234: Code to reproduce

Hi guys i have a question of ERC1155:

when i create a simply smart contract like this:

pragma solidity ^0.6.0;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC1155/ERC1155.sol";

contract Collections  is ERC1155 {
    address operator = msg.sender;
    
    uint256 private constant collect1 = 0;
    uint256 private constant collect2 = 1;
    uint256 private constant collect3 = 2;
    
    uint256[] listIds = [collect1,collect2,collect3]; 
    
    constructor() public ERC1155('https://5ea012a211b078001679d41f.mockapi.io/tokens/{id}'){
        
        
    }
    
    function createToken(address account, uint256[] memory ids, uint256[] memory amounts, bytes memory data) public {
        ids = listIds;
        _mintBatch(account, ids, amounts, data);
        
    }
    
    function getIds() public view returns(uint256[] memory){
        return listIds;
    }
    
}

when i mint the token i send this token to another account unlike operator address, but i can’t see the balance of token of account on etherscan, why? (i just use ropsten)

2 question: how to decide the mint of non-fungible token or fungible token? how to do this in _mint function??

1 Like

Hi @DeabitTech,

Welcome to the community forum :wave:
Thanks for posting here.

For OpenZeppelin Contracts you should only use code published in an official release. When importing via GitHub you should specify the release tag, otherwise you will get the latest code in the master branch. https://remix-ide.readthedocs.io/en/latest/import.html#importing-from-github

Please note, in your contract there is no access control, so any account could mint tokens.

Etherscan supports ERC20 and ERC721. Etherscan doesn’t currently support ERC1155, so it won’t show the token balances.

You can read the balances from the smart contract.

I deployed the following contract to Rinkeby and verified the smart contract source code.

We can use Etherscan’s read/write interface to interact with the token, including checking balances.

GameItems.sol

Remix version of example 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 "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.1.0/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, "");
    }
}

You may want to deploy this example and have a play with it to see what you can do with ERC1155. Also see the ERC1155 OpenZeppelin Contracts documentation: https://docs.openzeppelin.com/contracts/3.x/erc1155

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 above Silver, Gold, Silver, Swords and Shields are fungible, whilst Thors Hammer (as only one is minted) would be non-fungible.


You may want to look at the ERC1155 Preset contract as a way to get started.

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

Okay, i undestand all,
I just write a little articol (in italian language) on medium, see out of link:

Thank you for all

1 Like

Hi @DeabitTech,

Thanks for sharing your article.

Can you update your import in your article so that it imports from an official release of OpenZeppelin Contracts rather than the master branch?

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.1.0/contracts/token/ERC1155/ERC1155.sol";

sure https://medium.com/deabit/solidity-tutorial-multi-standard-token-erc-1155-25bf2c0a270e

1 Like

Hi @DeabitTech,

Would you like to post your article in #general:guides-and-tutorials

Hi @abcoathup,

Sure, thank you for opportunity!

1 Like