ERC-1155 Data Facet
View balances and approvals for ERC-1155 tokens
- Exposes external view functions for ERC-1155 data retrieval.
- Reads from shared diamond storage for token balances and approvals.
- Supports batched queries for efficiency.
- Includes
exportSelectorsfor diamond discovery.
Overview
This facet provides external read-only functions for ERC-1155 token balances and operator approvals within a diamond. It accesses shared diamond storage to retrieve this information, enabling consistent data retrieval across different facets. Developers integrate this facet to expose ERC-1155 data querying capabilities through the diamond proxy.
Storage
ERC1155Storage
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("erc1155")) |
Functions
balanceOf
Returns the amount of tokens of token type id owned by account.
Parameters:
| Property | Type | Description |
|---|---|---|
_account | address | The address to query the balance of. |
_id | uint256 | The token type to query. |
Returns:
| Property | Type | Description |
|---|---|---|
- | uint256 | The balance of the token type. |
balanceOfBatch
Batched version of balanceOf.
Parameters:
| Property | Type | Description |
|---|---|---|
_accounts | address[] | The addresses to query the balances of. |
_ids | uint256[] | The token types to query. |
Returns:
| Property | Type | Description |
|---|---|---|
balances | uint256[] | The balances of the token types. |
isApprovedForAll
Returns true if operator is approved to transfer account's tokens.
Parameters:
| Property | Type | Description |
|---|---|---|
_account | address | The token owner. |
_operator | address | The operator to query. |
Returns:
| Property | Type | Description |
|---|---|---|
- | bool | True if the operator is approved, false otherwise. |
exportSelectors
Exports the function selectors of the ERC1155DataFacet This function is use as a selector discovery mechanism for diamonds
Returns:
| Property | Type | Description |
|---|---|---|
- | bytes | selectors The exported function selectors of the ERC1155DataFacet |
Errors
Best Practices
- Ensure the
ERC1155DataFacetis added to the diamond with the correct selectors. - Use
balanceOfBatchfor efficient retrieval of multiple balances to minimize gas costs. - Verify that the
ERC1155ApproveFacetor equivalent is also deployed to manage approvals.
Security Considerations
This facet only exposes read-only functions. Input validation for array lengths is handled by the ERC1155InvalidArrayLength error in balanceOfBatch. Follow standard Solidity security practices for all interactions with the diamond.