简体   繁体   中英

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

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM