How to retrieve the data that ERC1155 is minted with?

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";

contract MyTest is ERC1155 {
    uint256 public constant GOLD = 0;

    constructor() ERC1155("https://game.example/api/item/{id}.json") {
        _mint(msg.sender, GOLD, 1, "yaaar 1");
        _mint(msg.sender, GOLD, 1, "yaaar 2");

How can I know whether my GOLD token was minted with “yaaar 1” or “yaaar 2”?

You can check and see if balanceOf(msg.sender, GOLD) returns 2, however, it would be unable to tell if the tokens are either yaaar 1 or yaaar 2 since they are in the data field.

Hi, welcome! :wave:

Maybe you can have a check the event:

TransferSingle(operator, address(0), account, id, amount);

Emmmm, I think for the function balanceOf() has two parameters:

function balanceOf(address account, uint256 id) {}

What do you think of it?

1 Like

Right, and thanks for making the correction. This is ERC1155, and balanceOf(msg.sender, GOLD) returns 2.

1 Like