ERC-1155 Approve Module
Internal ERC-1155 approval management
- All functions are
internalfor use within custom facets. - Uses the diamond storage pattern to manage approvals.
- Emits
ApprovalForAllevents for off-chain tracking. - No external dependencies or
usingdirectives within the module itself.
This module provides internal functions for use in your custom facets. Import it to access shared logic and storage.
Overview
This module provides internal functions for managing ERC-1155 token approvals. Facets can import this module to grant or revoke operator permissions using shared diamond storage. Changes made through this module are immediately visible to all facets interacting with the same storage.
Storage
ERC1155Storage
ERC-8042 compliant storage struct for ERC-1155 token data. storage-location: erc8042:erc1155
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("erc1155")) |
Functions
getStorage
Returns the ERC-1155 storage struct from the predefined diamond storage slot. Uses inline assembly to set the storage slot reference.
Returns:
| Property | Type | Description |
|---|---|---|
s | ERC1155Storage | The ERC-1155 storage struct reference. |
setApprovalForAll
Grants or revokes permission to operator to transfer the user's tokens. Emits an {ApprovalForAll} event.
Parameters:
| Property | Type | Description |
|---|---|---|
_user | address | The address of the token owner. |
_operator | address | The address to grant/revoke approval to. |
_approved | bool | True to approve, false to revoke. |
Events
Errors
Best Practices
- Ensure access control is enforced by the calling facet before invoking
setApprovalForAll. - Verify the
_operatoraddress is not the same as the_useraddress to prevent self-approval issues. - Handle the
ERC1155InvalidOperatorerror if the operator is invalid.
Integration Notes
This module interacts with diamond storage at the slot identified by keccak2535.keccak256(\"erc1155\"). The getStorage() function returns a reference to the ERC1155Storage struct, which is managed by the diamond. Any modifications to approvals via setApprovalForAll are written directly to this shared storage and are immediately visible to all other facets accessing the same storage slot.