Skip to main content

ERC-1155 Approve Facet

Manage ERC-1155 approvals within a diamond

Key Features
  • Exposes external setApprovalForAll function for diamond routing.
  • Emits ApprovalForAll event upon approval changes.
  • Uses inline assembly to access diamond storage.
  • Provides exportSelectors for diamond facet discovery.

Overview

This facet provides external functions for managing ERC-1155 token approvals within a diamond proxy. It integrates with diamond storage to track approval status. Developers add this facet to enable token holders to grant operators permission to transfer their ERC-1155 tokens.

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

setApprovalForAll

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

function setApprovalForAll(address _operator, bool _approved) external;

Parameters:

PropertyTypeDescription
_operatoraddressThe address to grant/revoke approval to.
_approvedboolTrue to approve, false to revoke.

exportSelectors

Exports the function selectors of the ERC1155ApproveFacet 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 ERC1155ApproveFacet

Events

Errors

Best Practices

Best Practice
  • Grant approvals only to trusted operators.
  • Ensure the ERC1155ApproveMod is correctly initialized before this facet is used.
  • Verify that the diamond storage layout is compatible before upgrading.

Security Considerations

Security

The setApprovalForAll function allows any caller to approve or revoke an operator for their tokens. Callers must ensure they are approving legitimate operators. The facet includes an ERC1155InvalidOperator error, which is currently not used by the exposed functions, but is available for internal use or future extensions.

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.