ERC1155 check if token owner

My generaI question: Is there a method in ERC1155 that is equivalent to the method of ERC721 “ownerOf(tokenId)”

:computer: Environment
@openzeppelin/contracts-upgradeable”: “^4.1.0”,


How would I control that only the token owner has “access” to this function (incrementCurrentLockedContentViewTracker and emit the event LockedContentViewed)

function getLockedContent(address account, uint256 tokenId)
   // require(
   //     account == _msgSender() || isApprovedForAll(account, _msgSender()),
   //     "ERC1155: caller is not owner nor approved"
   // );
	emit LockedContentViewed(msg.sender, tokenId, _lockedContent[tokenId]);

Maybe no.

Maybe you can use balanceOf(account, id) to check whether account is a owner of id, cause if account own id, the return value is not equal to 0.

BTW, you can find all common function in ERC1155 at here:

1 Like


implemented it like this:

function _ownerOf(uint256 tokenId) internal view returns (bool) {
    return balanceOf(msg.sender, tokenId) != 0;