Skip to main content

ERC-1155 Data Facet

View balances and approvals for ERC-1155 tokens

Key Features
  • 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 exportSelectors for 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

Definition
struct ERC1155Storage {
mapping(uint256 id => mapping(address account => uint256 balance)) balanceOf;
mapping(address account => mapping(address operator => bool)) isApprovedForAll;
}

State Variables

PropertyTypeDescription
STORAGE_POSITIONbytes32Diamond storage slot position for this module (Value: keccak256("erc1155"))

Functions

balanceOf

Returns the amount of tokens of token type id owned by account.

function balanceOf(address _account, uint256 _id) external view returns (uint256);

Parameters:

PropertyTypeDescription
_accountaddressThe address to query the balance of.
_iduint256The token type to query.

Returns:

PropertyTypeDescription
-uint256The balance of the token type.

balanceOfBatch

Batched version of balanceOf.

function balanceOfBatch(address[] calldata _accounts, uint256[] calldata _ids)
external
view
returns (uint256[] memory balances);

Parameters:

PropertyTypeDescription
_accountsaddress[]The addresses to query the balances of.
_idsuint256[]The token types to query.

Returns:

PropertyTypeDescription
balancesuint256[]The balances of the token types.

isApprovedForAll

Returns true if operator is approved to transfer account's tokens.

function isApprovedForAll(address _account, address _operator) external view returns (bool);

Parameters:

PropertyTypeDescription
_accountaddressThe token owner.
_operatoraddressThe operator to query.

Returns:

PropertyTypeDescription
-boolTrue 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

function exportSelectors() external pure returns (bytes memory);

Returns:

PropertyTypeDescription
-bytesselectors The exported function selectors of the ERC1155DataFacet

Errors

Best Practices

Best Practice
  • Ensure the ERC1155DataFacet is added to the diamond with the correct selectors.
  • Use balanceOfBatch for efficient retrieval of multiple balances to minimize gas costs.
  • Verify that the ERC1155ApproveFacet or equivalent is also deployed to manage approvals.

Security Considerations

Security

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.

Was this helpful?
Last updated:

Newsletter

Get notified about releases, feature announcements, and technical deep-dives on building smart contracts with Compose.

No spam. Unsubscribe anytime.