0

I was looking for simple implementation of checking balanceOf ERC1155 with given _tokenId using openzeppelin library but I haven't found any. Please Help me how can I use this method in smartcontract by showing any smple function with correct constructor settings

function balanceOf(address owner) external view returns (uint256);

2 Answers 2

1

You should be able to use the balanceOf function defined in EIP-1155. This is also available on the OpenZepplin implementation: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC1155/ERC1155.sol#L70

0

Thanks, I made function:

function getTokenBalance(address _contractAddr, uint256 _tokenId) view public returns (uint256) {
    ERC1155 token = ERC1155(_contractAddr);
    return token.balanceOf(msg.sender, _tokenId);
}
1
  • I will move it to mapping addr -> balances if it ill be necessery. Commented Jan 9, 2022 at 0:17

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.