ERC1155Lib
Title: ERC1155Lib
Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC1155/ERC1155.sol)
Library implementing the ERC-1155 Multi-Token Standard.
Mirrors OpenZeppelin v5.6.1 ERC1155 logic. All state lives in an ERC-7201 slot. Differences: no
_setApprovalForAll(owner, ...) variant (approval always uses msg.sender, so OZ's owner-zero check
cannot fire) and no five-argument _updateWithAcceptanceCheck overload.
Hook model (decision D25, #234): _update calls no extension hook. An extension that gates or observes
movement (Pausable, Supply) must replace the public safeTransferFrom/safeBatchTransferFrom selectors
instead, and two such extensions are mutually exclusive. A caller of _mint/_burn/_update outside
those selectors (ERC1155Burnable) bypasses them.
See docs/guides/selector-compatibility.md#token-extension-hook-model.
Functions
erc1155Storage
function erc1155Storage() internal pure returns (ERC1155Storage storage $);Returns
| Name | Type | Description |
|---|---|---|
| $ | ERC1155Storage |
__ERC1155_init
Initializes the ERC-1155 module with a URI template.
Must be called inside a pre/postInitializer block.
function __ERC1155_init(string memory uri_) internal;Parameters
| Name | Type | Description |
|---|---|---|
| uri_ | string |
registerInterfaces
Registers support for IERC1155 and IERC1155MetadataURI interfaces via ERC-165.
function registerInterfaces() internal;uri
Returns the URI for token type id.
Consumers can override to substitute id in the template.
function uri(
uint256 /*id*/
)
internal
view
returns (string memory);Parameters
| Name | Type | Description |
|---|---|---|
| _ | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | string |
balanceOf
Returns the balance of account for token type id.
function balanceOf(address account, uint256 id) internal view returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| account | address | |
| id | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
balanceOfBatch
Batched version of balanceOf.
function balanceOfBatch(address[] memory accounts, uint256[] memory ids) internal view returns (uint256[] memory);Parameters
| Name | Type | Description |
|---|---|---|
| accounts | address[] | |
| ids | uint256[] |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256[] |
isApprovedForAll
Returns true if operator is approved to transfer account's tokens.
function isApprovedForAll(address account, address operator) internal view returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| account | address | |
| operator | address |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
setApprovalForAll
Grants or revokes permission to operator.
function setApprovalForAll(address operator, bool approved) internal;Parameters
| Name | Type | Description |
|---|---|---|
| operator | address | |
| approved | bool |
safeTransferFrom
Transfers value of token id from from to to.
function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes memory data) internal;Parameters
| Name | Type | Description |
|---|---|---|
| from | address | |
| to | address | |
| id | uint256 | |
| value | uint256 | |
| data | bytes |
safeBatchTransferFrom
Batch transfers tokens.
function safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory values,
bytes memory data
) internal;Parameters
| Name | Type | Description |
|---|---|---|
| from | address | |
| to | address | |
| ids | uint256[] | |
| values | uint256[] | |
| data | bytes |
_checkAuthorized
Reverts with IERC1155.ERC1155MissingApprovalForAll unless operator is owner or an
approved operator of owner.
function _checkAuthorized(address operator, address owner) internal view;Parameters
| Name | Type | Description |
|---|---|---|
| operator | address | |
| owner | address |
_safeTransferFrom
Internal safe single transfer. Validates receiver.
function _safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes memory data) internal;Parameters
| Name | Type | Description |
|---|---|---|
| from | address | |
| to | address | |
| id | uint256 | |
| value | uint256 | |
| data | bytes |
_safeBatchTransferFrom
Internal safe batch transfer. Validates receiver.
function _safeBatchTransferFrom(
address from,
address to,
uint256[] memory ids,
uint256[] memory values,
bytes memory data
) internal;Parameters
| Name | Type | Description |
|---|---|---|
| from | address | |
| to | address | |
| ids | uint256[] | |
| values | uint256[] | |
| data | bytes |
_update
Central state mutation. Validates array lengths, adjusts balances, emits events.
Runs no extension hook (D25).
function _update(address from, address to, uint256[] memory ids, uint256[] memory values) internal;Parameters
| Name | Type | Description |
|---|---|---|
| from | address | |
| to | address | |
| ids | uint256[] | |
| values | uint256[] |
_mint
Mints value of token id to to.
function _mint(address to, uint256 id, uint256 value, bytes memory data) internal;Parameters
| Name | Type | Description |
|---|---|---|
| to | address | |
| id | uint256 | |
| value | uint256 | |
| data | bytes |
_mintBatch
Batch mints tokens to to.
function _mintBatch(address to, uint256[] memory ids, uint256[] memory values, bytes memory data) internal;Parameters
| Name | Type | Description |
|---|---|---|
| to | address | |
| ids | uint256[] | |
| values | uint256[] | |
| data | bytes |
_burn
Burns value of token id from from.
function _burn(address from, uint256 id, uint256 value) internal;Parameters
| Name | Type | Description |
|---|---|---|
| from | address | |
| id | uint256 | |
| value | uint256 |
_burnBatch
Batch burns tokens from from.
function _burnBatch(address from, uint256[] memory ids, uint256[] memory values) internal;Parameters
| Name | Type | Description |
|---|---|---|
| from | address | |
| ids | uint256[] | |
| values | uint256[] |
_updateWithAcceptanceCheck
Updates balances, then runs the ERC-1155 receiver acceptance check when to is not the zero
address. Every ERC1155Lib transfer, mint and burn path routes through here, as in OpenZeppelin
v5.6.1 (ERC1155PausableLib too, after its pause check). ERC1155SupplyLib carries its own copy,
which writes the supply counters between _update and the receiver check.
batch names the operation type and alone picks the receiver hook: a batch operation calls
onERC1155BatchReceived even with a single id, and a single operation calls onERC1155Received.
OpenZeppelin v5.6.1 also keeps a five-argument overload that infers batch from ids.length != 1
for backwards compatibility; it is not ported, so no caller can pick the hook by array length.
function _updateWithAcceptanceCheck(
address from,
address to,
uint256[] memory ids,
uint256[] memory values,
bytes memory data,
bool batch
) internal;Parameters
| Name | Type | Description |
|---|---|---|
| from | address | |
| to | address | |
| ids | uint256[] | |
| values | uint256[] | |
| data | bytes | |
| batch | bool | True for safeBatchTransferFrom, _mintBatch and _burnBatch. |
_doSafeTransferAcceptanceCheck
Calls IERC1155Receiver.onERC1155Received if to is a contract.
Distinguishes between a non-implementor (empty revert) and a deliberate revert from the receiver (non-empty reason). Non-empty reasons are re-bubbled verbatim so callers see the actual error from the receiver contract.
function _doSafeTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256 id,
uint256 value,
bytes memory data
) internal;Parameters
| Name | Type | Description |
|---|---|---|
| operator | address | |
| from | address | |
| to | address | |
| id | uint256 | |
| value | uint256 | |
| data | bytes |
_doSafeBatchTransferAcceptanceCheck
Calls IERC1155Receiver.onERC1155BatchReceived if to is a contract.
Distinguishes between a non-implementor (empty revert) and a deliberate revert from the receiver (non-empty reason). Non-empty reasons are re-bubbled verbatim so callers see the actual error from the receiver contract.
function _doSafeBatchTransferAcceptanceCheck(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory values,
bytes memory data
) internal;Parameters
| Name | Type | Description |
|---|---|---|
| operator | address | |
| from | address | |
| to | address | |
| ids | uint256[] | |
| values | uint256[] | |
| data | bytes |
_asSingletonArray
function _asSingletonArray(uint256 element) internal pure returns (uint256[] memory arr);Parameters
| Name | Type | Description |
|---|---|---|
| element | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| arr | uint256[] |