1

Im trying to track in real time the holders of any ERC1155 contract, and I have this doubt about this interface.

The ERC1155 can work as an NFT or as a Token, but also as both at the same time, right?

If it do, Is there any other way to know if a transaction involves NFTs or tokens as part of checking if the value of the transaction is 1 or not?

Thanks!

Edit 1: Reading the oficial specification of the ERC1155 I found the following:

The following strategies are examples of how you MAY mix fungible and non-fungible tokens together in the same contract. The standard does NOT mandate how an implementation must do this.

Also they propose a posible implementation of how to mix both uses cases:

The top 128 bits of the uint256 _id parameter in any ERC-1155 function MAY represent the base token ID, while the bottom 128 bits MAY represent the index of the non-fungible to make it unique.

uint256 baseTokenNFT = 12345 << 128;
uint128 indexNFT = 50;

uint256 baseTokenFT = 54321 << 128;

balanceOf(msg.sender, baseTokenNFT); // Get balance of the base token for non-fungible set 12345 (this MAY be used to get balance of the user for all of this token set if the implementation wishes as a convenience).
balanceOf(msg.sender, baseTokenNFT + indexNFT); // Get balance of the token at index 50 for non-fungible set 12345 (should be 1 if user owns the individual non-fungible token or 0 if they do not).
balanceOf(msg.sender, baseTokenFT); // Get balance of the fungible base token 54321.

1 Answer 1

0

The best way to track holders of ERC1155 tokens is to track those two events defined in ERC1155 specifications :

  • event TransferSingle(address indexed _operator, address indexed _from, address indexed _to, uint256 _id, uint256 _value);
  • event TransferBatch(address indexed _operator, address indexed _from, address indexed _to, uint256[] _ids, uint256[] _values);

Make sure these events are well implemented in the transfer function of the token's smart contract you want to track.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.