📖 Scenario: You are creating a simple blockchain contract to manage multiple types of tokens in one place. This is useful for games or collectibles where you want to handle many items efficiently.
🎯 Goal: Build a basic ERC-1155 contract that can hold different token types and allow minting new tokens.
📋 What You'll Learn
Create a contract named MyMultiToken that inherits from ERC1155
Set the base URI to https://token-cdn-domain/{id}.json
Create a public function mint that allows minting a specific amount of a token ID to an address
Use the _mint function from ERC1155 inside mint
Print the token URI for a given token ID
💡 Why This Matters
🌍 Real World
ERC-1155 contracts are used in blockchain games and digital collectibles to manage many token types efficiently in one contract.
💼 Career
Understanding ERC-1155 is important for blockchain developers working on NFTs, gaming, and multi-token platforms.
Progress0 / 4 steps
1
Set up the ERC-1155 contract
Write a Solidity contract named MyMultiToken that inherits from ERC1155. Set the constructor to call ERC1155 with the URI "https://token-cdn-domain/{id}.json".
Blockchain / Solidity
Hint
Use contract MyMultiToken is ERC1155 and call the parent constructor with the URI.
2
Add a mint function
Add a public function named mint that takes address to, uint256 id, and uint256 amount as parameters. Inside it, call _mint(to, id, amount, "").
Blockchain / Solidity
Hint
Create a mint function that calls _mint with the given parameters and empty data.
3
Add a function to get token URI
Add a public view function named getTokenURI that takes uint256 id and returns a string memory. Inside, return the result of uri(id).
Blockchain / Solidity
Hint
Use the inherited uri function to get the token URI for the given id.
4
Test minting and getting token URI
Write a comment showing how to call mint to mint 10 tokens of ID 1 to address 0x123.... Then write a comment showing how to call getTokenURI for token ID 1.
Blockchain / Solidity
Hint
Show example calls as comments with the exact address and token ID.
Practice
(1/5)
1. What is the main advantage of the ERC-1155 token standard compared to ERC-20 and ERC-721?
easy
A. It only supports fungible tokens.
B. It allows managing multiple token types in a single contract.
C. It is designed exclusively for non-fungible tokens.
D. It requires a separate contract for each token type.
Solution
Step 1: Understand ERC-20 and ERC-721 limitations
ERC-20 supports fungible tokens only, and ERC-721 supports non-fungible tokens but each token type needs its own contract.
Step 2: Identify ERC-1155 feature
ERC-1155 allows multiple token types (fungible and non-fungible) to be managed within a single contract efficiently.
Final Answer:
It allows managing multiple token types in a single contract. -> Option B
Quick Check:
ERC-1155 = multi-token single contract [OK]
Hint: ERC-1155 = many tokens, one contract [OK]
Common Mistakes:
Thinking ERC-1155 supports only one token type
Confusing ERC-1155 with ERC-20 or ERC-721
Believing ERC-1155 requires multiple contracts
2. Which of the following is the correct Solidity function signature to mint multiple tokens in ERC-1155?
easy
A. function mintBatch(address to, uint256[] ids, uint256[] amounts, bytes data) external;
B. function mintToken(address to, uint256 id) external;
C. function mint(address to, uint256 id, uint256 amount, bytes data) external;
D. function mintSingle(address to, uint256 id, uint256 amount) external;
Solution
Step 1: Recall ERC-1155 minting functions
ERC-1155 defines mintBatch to mint multiple token types at once, taking arrays of ids and amounts.
Step 2: Match function signature
function mintBatch(address to, uint256[] ids, uint256[] amounts, bytes data) external; matches the standard signature: mintBatch(address to, uint256[] ids, uint256[] amounts, bytes data).
Final Answer:
function mintBatch(address to, uint256[] ids, uint256[] amounts, bytes data) external; -> Option A
Quick Check:
mintBatch = batch minting function [OK]
Hint: Batch mint uses arrays of ids and amounts [OK]
Common Mistakes:
Using single id and amount for batch mint
Confusing mintBatch with mintSingle
Missing bytes data parameter
3. Given the following Solidity snippet, what will be the balance of token ID 5 for address 0xABC after execution?
5. You want to create a game inventory using ERC-1155 where players can hold multiple types of items. Which approach best uses ERC-1155 features to efficiently track and transfer items?
hard
A. Deploy one ERC-1155 contract with unique IDs for each item type and use batch transfers for multiple items.
B. Deploy separate ERC-721 contracts for each item type and transfer items individually.
C. Use ERC-20 tokens for each item type and transfer amounts representing item counts.
D. Create one ERC-1155 contract but mint only one token type for all items.
Solution
Step 1: Understand game inventory needs
Players hold many item types, needing efficient tracking and transfers.
Step 2: Evaluate ERC-1155 advantages
ERC-1155 supports multiple token IDs in one contract and batch transfers, reducing gas and complexity.
Step 3: Compare options
Deploy one ERC-1155 contract with unique IDs for each item type and use batch transfers for multiple items. uses one contract with unique IDs and batch transfers, matching ERC-1155 strengths. Others use less efficient or wrong standards.
Final Answer:
Deploy one ERC-1155 contract with unique IDs for each item type and use batch transfers for multiple items. -> Option A
Quick Check:
One contract + batch transfers = efficient multi-item management [OK]
Hint: Use one ERC-1155 contract with batch transfers for many items [OK]
Common Mistakes:
Using multiple contracts unnecessarily
Choosing ERC-20 or ERC-721 for multi-item inventory
Minting only one token type for all items
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.