Skip to content
Lattice

ERC1155Lib

Git Source

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

NameTypeDescription
$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

NameTypeDescription
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

NameTypeDescription
_uint256

Returns

NameTypeDescription
<none>string

balanceOf

Returns the balance of account for token type id.

function balanceOf(address account, uint256 id) internal view returns (uint256);

Parameters

NameTypeDescription
accountaddress
iduint256

Returns

NameTypeDescription
<none>uint256

balanceOfBatch

Batched version of balanceOf.

function balanceOfBatch(address[] memory accounts, uint256[] memory ids) internal view returns (uint256[] memory);

Parameters

NameTypeDescription
accountsaddress[]
idsuint256[]

Returns

NameTypeDescription
<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

NameTypeDescription
accountaddress
operatoraddress

Returns

NameTypeDescription
<none>bool

setApprovalForAll

Grants or revokes permission to operator.

function setApprovalForAll(address operator, bool approved) internal;

Parameters

NameTypeDescription
operatoraddress
approvedbool

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

NameTypeDescription
fromaddress
toaddress
iduint256
valueuint256
databytes

safeBatchTransferFrom

Batch transfers tokens.

function safeBatchTransferFrom(
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory values,
        bytes memory data
    ) internal;

Parameters

NameTypeDescription
fromaddress
toaddress
idsuint256[]
valuesuint256[]
databytes

_checkAuthorized

Reverts with IERC1155.ERC1155MissingApprovalForAll unless operator is owner or an approved operator of owner.

function _checkAuthorized(address operator, address owner) internal view;

Parameters

NameTypeDescription
operatoraddress
owneraddress

_safeTransferFrom

Internal safe single transfer. Validates receiver.

function _safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes memory data) internal;

Parameters

NameTypeDescription
fromaddress
toaddress
iduint256
valueuint256
databytes

_safeBatchTransferFrom

Internal safe batch transfer. Validates receiver.

function _safeBatchTransferFrom(
        address from,
        address to,
        uint256[] memory ids,
        uint256[] memory values,
        bytes memory data
    ) internal;

Parameters

NameTypeDescription
fromaddress
toaddress
idsuint256[]
valuesuint256[]
databytes

_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

NameTypeDescription
fromaddress
toaddress
idsuint256[]
valuesuint256[]

_mint

Mints value of token id to to.

function _mint(address to, uint256 id, uint256 value, bytes memory data) internal;

Parameters

NameTypeDescription
toaddress
iduint256
valueuint256
databytes

_mintBatch

Batch mints tokens to to.

function _mintBatch(address to, uint256[] memory ids, uint256[] memory values, bytes memory data) internal;

Parameters

NameTypeDescription
toaddress
idsuint256[]
valuesuint256[]
databytes

_burn

Burns value of token id from from.

function _burn(address from, uint256 id, uint256 value) internal;

Parameters

NameTypeDescription
fromaddress
iduint256
valueuint256

_burnBatch

Batch burns tokens from from.

function _burnBatch(address from, uint256[] memory ids, uint256[] memory values) internal;

Parameters

NameTypeDescription
fromaddress
idsuint256[]
valuesuint256[]

_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

NameTypeDescription
fromaddress
toaddress
idsuint256[]
valuesuint256[]
databytes
batchboolTrue 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

NameTypeDescription
operatoraddress
fromaddress
toaddress
iduint256
valueuint256
databytes

_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

NameTypeDescription
operatoraddress
fromaddress
toaddress
idsuint256[]
valuesuint256[]
databytes

_asSingletonArray

function _asSingletonArray(uint256 element) internal pure returns (uint256[] memory arr);

Parameters

NameTypeDescription
elementuint256

Returns

NameTypeDescription
arruint256[]