ERC1155 Token Ownership – How to Verify if User Owns Token?

erc-1155nftsoliditytokens

I have a ERC1155 collection on opensea and I am trying to perform a check in my contract to see if the user owns any tokens from the collection, and how many. With ERC721 I was able to do this but I'm having issues with ERC1155 balanceOf –

require(IERC1155(0x00...).balanceOf(msg.sender) >= 1, "No tokens owned!");

I don't have the exact tokenID because it varies depending on what the user owns. How can I perform a check?

EDIT

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";

import "@openzeppelin/contracts/access/Ownable.sol";

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

contract test is ERC721URIStorage, Ownable {

using Strings for uint256;

constructor() ERC721("TEST", "TEST") {}

function viewBalance() external view returns (uint256) {return IERC1155(contractAddress).balanceOf(userAddress,tokenID);}

}

contractAddress, userAddress, tokenID – used as placeholders for the post. I'm placing the values directly in my code.

Best Answer

Unfortunately, you have to specify token id in erc1155. There is no way for doing it to a standard erc1155 contract.

Related Topic