ERC-1155 Transfer Facet
ERC-1155 token transfers within a diamond
- Implements
safeTransferFromandsafeBatchTransferFromfor ERC-1155 token handling. - Accesses shared diamond storage via
getStorage()for balance management. - Emits
TransferSingleandTransferBatchevents for off-chain tracking. - Exports its function selectors via
exportSelectors()for diamond integration.
Overview
This facet implements ERC-1155 token transfers as external functions callable through a diamond proxy. It accesses shared diamond storage to manage token balances and emits standard events for off-chain consumption. Developers integrate this facet to provide core ERC-1155 transfer capabilities while retaining diamond's upgradeability.
Storage
ERC1155Storage
State Variables
| Property | Type | Description |
|---|---|---|
STORAGE_POSITION | bytes32 | Diamond storage slot position for this module (Value: keccak256("erc1155")) |
Functions
safeTransferFrom
Transfers value amount of token type id from from to to. Emits a TransferSingle event.
Parameters:
| Property | Type | Description |
|---|---|---|
_from | address | The address to transfer from. |
_to | address | The address to transfer to. |
_id | uint256 | The token type to transfer. |
_value | uint256 | The amount to transfer. |
_data | bytes | Additional data with no specified format. |
safeBatchTransferFrom
Batched version of safeTransferFrom. Emits a TransferBatch event.
Parameters:
| Property | Type | Description |
|---|---|---|
_from | address | The address to transfer from. |
_to | address | The address to transfer to. |
_ids | uint256[] | The token types to transfer. |
_values | uint256[] | The amounts to transfer. |
_data | bytes | Additional data with no specified format. |
exportSelectors
Exports the function selectors of the ERC1155TransferFacet This function is use as a selector discovery mechanism for diamonds
Returns:
| Property | Type | Description |
|---|---|---|
- | bytes | selectors The exported function selectors of the ERC1155TransferFacet |
Events
Errors
Best Practices
- Ensure the
ERC1155Storagestruct is correctly initialized in diamond storage before deploying this facet. - Verify that the
ERC1155ApproveFacetis also deployed to manage approvals required for transfers. - Call
exportSelectors()during diamond deployment to register the facet's functions.
Security Considerations
The safeTransferFrom and safeBatchTransferFrom functions perform checks before state changes and external interactions, mitigating reentrancy risks. Input validation is performed for sender, receiver, and array lengths, reverting with custom errors like ERC1155InvalidSender and ERC1155InvalidArrayLength. Ensure that the caller has the necessary approvals via ERC1155ApproveFacet before invoking transfer functions.