How to check whether user has any ERC1155 of specific contract in solidity?

694 views Asked by At

I'm writing a staking smart-contract for ERC1155 contract (https://etherscan.io/address/0x2013ff029f9d3d31169f4fdc673c8b9fa0ce1fbd#code). When user wants to claim his reward, I need to check whether he owns any token of another ERC721 contract (https://etherscan.io/address/0x50add0f8541df53765848f6c73fecdc794fff985#code) to reward him with extra 10% of earned tokens. I can easily do it, using balanceOf of ERC721. If it returns 0, then user doesn't have any NFTs, so he won't get any extra tokens.

What would I do if bonus contract wasn't ERC721, but ERC1155? balanceOf of ERC1155 works in other way, it shows how many tokens of given id user has, when ERC721 shows total amount of tokens user owns. How could I check whether user has any ERC1155 of given contract?

1

There are 1 answers

1
chixx.eth On BEST ANSWER

You can do a loop with balanceOf and increment the id or use balanceOfBatch. But I see on the contract you only have one collection => TOKEN_ID == 0, so u can use balanceOf.