Skip to main content

ERC-1155 Approve Module

Internal ERC-1155 approval management

Key Features
  • All functions are internal for use within custom facets.
  • Uses the diamond storage pattern to manage approvals.
  • Emits ApprovalForAll events for off-chain tracking.
  • No external dependencies or using directives within the module itself.
Module Usage

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

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

getStorage

Returns the ERC-1155 storage struct from the predefined diamond storage slot. Uses inline assembly to set the storage slot reference.

function getStorage() pure returns (ERC1155Storage storage s);

Returns:

PropertyTypeDescription
sERC1155StorageThe ERC-1155 storage struct reference.

setApprovalForAll

Grants or revokes permission to operator to transfer the user's tokens. Emits an {ApprovalForAll} event.

function setApprovalForAll(address _user, address _operator, bool _approved) ;

Parameters:

PropertyTypeDescription
_useraddressThe address of the token owner.
_operatoraddressThe address to grant/revoke approval to.
_approvedboolTrue to approve, false to revoke.

Events

Errors

Best Practices

Best Practice
  • Ensure access control is enforced by the calling facet before invoking setApprovalForAll.
  • Verify the _operator address is not the same as the _user address to prevent self-approval issues.
  • Handle the ERC1155InvalidOperator error if the operator is invalid.

Integration Notes

Shared Storage

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.

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.