ERC1155’s distinctive feature is its ability to represent multiple tokens using a single smart contract. This is different from ERC20 since the balanceOf function requires an id argument to query a specific token’s balance. Unlike ERC721, which deals with non-fungible tokens, ERC1155 assigns a unique balance for each token id and creates non-fungible tokens by minting a single instance. This approach significantly reduces gas costs by allowing a single contract to hold the system state, making it more cost-effective and less complex than deploying a new contract for each token type.

Once we have imported PHX network, lets deploy a tokenized ERC1155 contract!

*Note that we will be using OpenZeppelin SDK (https://docs.openzeppelin.com/) for this example.*

Here is an example of our ERC1155 contract:

// contracts/RareThings.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import “@openzeppelin/contracts/token/ERC1155/ERC1155.sol”;

contract RareThings is ERC1155 {
uint256 public constant DIAMOND = 0;
uint256 public constant PLATINUM = 1;
uint256 public constant GOLD_DUCK = 2;

constructor() ERC1155(“JSON_DOCUMENT_LINK”) {
_mint(msg.sender, DIAMOND, 10**10, “”);
_mint(msg.sender, PLATINUM, 10**20, “”);
_mint(msg.sender, GOLD_DUCK, 1, “”);
}
}

*Note that for Rare Things, Diamond is a fungible token and Gold Duck is a non-fungible token since only one was minted.*

Metadata uri can be fetched with:
> gameItems.uri(2)
“JSON_DOCUMENT_LINK”

Here is an example of Metadata token ID 2 in JSON document:

{
“name”: “Golden Duck”,
“image”: “IPFS-URL_GOES_HERE”,
“description”: “The brightest of Ducks gleaming in the sunlight”,
“external_url”: “EXTERNAL_URL_GOES_HERE, like your website or social media account”,
“attributes”: [
{
“value”: “Golden Worthy”,
“trait_type”: “Rarity”
},
{
“value”: “Golden Laser Eyes”,
“trait_type”: “Weapon”
},
{
“value”: “Golden Shoulder Pads”,
“trait_type”: “Armor”
},
{
“value”: “Golden Shine”,
“trait_type”: “Style”
}
],
“artist”: “ARTIST_NAME_GOES_HERE”
}

For a list of full commands available on ERC 1155, reference:
https://eips.ethereum.org/EIPS/eip-1155