0
0
Blockchain / Solidityprogramming~20 mins

ERC-1155 multi-token standard in Blockchain / Solidity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ERC-1155 Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this ERC-1155 balance query?

Consider the following Solidity snippet querying balances of tokens in an ERC-1155 contract. What will be the output of the balances array?

Blockchain / Solidity
contract Test {
    function getBalances(address erc1155, address user) public view returns (uint256[] memory) {
        uint256[] memory ids = new uint256[](3);
        ids[0] = 1;
        ids[1] = 2;
        ids[2] = 3;
        return IERC1155(erc1155).balanceOfBatch(_fillArray(user, 3), ids);
    }
    
    function _fillArray(address user, uint256 length) internal pure returns (address[] memory) {
        address[] memory arr = new address[](length);
        for (uint256 i = 0; i < length; i++) {
            arr[i] = user;
        }
        return arr;
    }
}

interface IERC1155 {
    function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids) external view returns (uint256[] memory);
}
A[10, 0, 5]
B[10, 5, 0]
C[0, 0, 0]
DCompilation error due to _fillArray visibility
Attempts:
2 left
💡 Hint

Remember that balanceOfBatch returns balances in the order of the input arrays.

🧠 Conceptual
intermediate
1:30remaining
Which feature distinguishes ERC-1155 from ERC-20 and ERC-721?

ERC-1155 is a multi-token standard. What key feature makes it different from ERC-20 and ERC-721?

AOnly supports fungible tokens with decimals
BSupports multiple token types (fungible and non-fungible) in a single contract
CRequires separate contracts for each token type
DDoes not support batch transfers
Attempts:
2 left
💡 Hint

Think about how many token types can be managed by one contract.

🔧 Debug
advanced
2:30remaining
Why does this batch transfer revert in ERC-1155?

Given this Solidity code snippet for batch transfer, why does the transaction revert?

Blockchain / Solidity
function safeBatchTransferFrom(
    address from,
    address to,
    uint256[] memory ids,
    uint256[] memory amounts,
    bytes memory data
) public {
    require(ids.length == amounts.length, "IDs and amounts length mismatch");
    for (uint256 i = 0; i < ids.length; i++) {
        require(balanceOf(from, ids[i]) >= amounts[i], "Insufficient balance");
        _balances[ids[i]][from] -= amounts[i];
        _balances[ids[i]][to] += amounts[i];
    }
    emit TransferBatch(msg.sender, from, to, ids, amounts);
}
AThe function lacks a check for 'to' being a valid address
BThe balances mapping is indexed incorrectly causing underflow
CThe function does not call _doSafeBatchTransferAcceptanceCheck, so it reverts on safe transfers to contracts
DThe require statement comparing ids and amounts lengths is incorrect
Attempts:
2 left
💡 Hint

ERC-1155 safe transfers require acceptance checks when sending to contracts.

📝 Syntax
advanced
1:30remaining
Identify the syntax error in this ERC-1155 mint function

What is the syntax error in this mint function snippet?

Blockchain / Solidity
function mint(address to, uint256 id, uint256 amount, bytes memory data) public {
    require(to != address(0), "Mint to zero address");
    _balances[id][to] += amount;
    emit TransferSingle(msg.sender, address(0), to, id, amount);
    _doSafeTransferAcceptanceCheck(msg.sender, address(0), to, id, amount, data);
}
AFunction lacks visibility specifier
BIncorrect event name TransferSingle should be TransferBatch
CIncorrect order of parameters in _doSafeTransferAcceptanceCheck
DMissing semicolon after updating _balances
Attempts:
2 left
💡 Hint

Check each line for missing punctuation.

🚀 Application
expert
2:00remaining
How many items are in the resulting balances array after batch mint?

An ERC-1155 contract mints tokens in batch with the following call:

mintBatch(user, [1,2,3,4], [10,0,5,7], "0x")

What is the length of the balances array returned by balanceOfBatch when querying for user balances of token IDs [1,2,3,4]?

A4
B3
C0
D1
Attempts:
2 left
💡 Hint

The length of the balances array matches the number of token IDs queried.