Skip to main content

ERC1155

Git Source

Authors: Axicon Labs Limited, Modified from Solmate (https://github.com/transmissions11/solmate/blob/v7/src/tokens/ERC1155.sol)

Not compliant to the letter, does not include any metadata functionality.

State Variables
​

balanceOf
​

Token balances for each user.

Indexed by user, then by token id.

mapping(address account => mapping(uint256 tokenId => uint256 balance)) public balanceOf;

isApprovedForAll
​

Approved addresses for each user.

Indexed by user, then by operator.

Operator is approved to transfer all tokens on behalf of user.

mapping(address owner => mapping(address operator => bool approvedForAll)) public isApprovedForAll;

Functions
​

setApprovalForAll
​

Approve or revoke approval for operator to transfer all tokens on behalf of the caller.

function setApprovalForAll(address operator, bool approved) public;

Parameters

NameTypeDescription
operatoraddressThe address to approve or revoke approval for
approvedboolTrue to approve, false to revoke approval

safeTransferFrom
​

Transfer a single token from one user to another.

Supports approved token transfers.

function safeTransferFrom(address from, address to, uint256 id, uint256 amount, bytes calldata data) public virtual;

Parameters

NameTypeDescription
fromaddressThe user to transfer tokens from
toaddressThe user to transfer tokens to
iduint256The ERC1155 token id to transfer
amountuint256The amount of tokens to transfer
databytesOptional data to include in the onERC1155Received hook

safeBatchTransferFrom
​

Transfer multiple tokens from one user to another.

Supports approved token transfers.

ids and amounts must be of equal length.

function safeBatchTransferFrom(
address from,
address to,
uint256[] calldata ids,
uint256[] calldata amounts,
bytes calldata data
) public virtual;

Parameters

NameTypeDescription
fromaddressThe user to transfer tokens from
toaddressThe user to transfer tokens to
idsuint256[]The ERC1155 token ids to transfer
amountsuint256[]The amounts of tokens to transfer
databytesOptional data to include in the onERC1155Received hook

balanceOfBatch
​

Query balances for multiple users and tokens at once.

owners and ids should be of equal length.

function balanceOfBatch(address[] calldata owners, uint256[] calldata ids)
public
view
returns (uint256[] memory balances);

Parameters

NameTypeDescription
ownersaddress[]The list of users to query balances for
idsuint256[]The list of ERC1155 token ids to query

Returns

NameTypeDescription
balancesuint256[]The balances for each owner-id pair in the same order as the input arrays

supportsInterface
​

Signal support for ERC165 and ERC1155.

function supportsInterface(bytes4 interfaceId) public pure returns (bool);

Parameters

NameTypeDescription
interfaceIdbytes4The interface to check for support

Returns

NameTypeDescription
<none>boolWhether the interface is supported

_mint
​

Internal utility to mint tokens to a user's account.

function _mint(address to, uint256 id, uint256 amount) internal;

Parameters

NameTypeDescription
toaddressThe user to mint tokens to
iduint256The ERC1155 token id to mint
amountuint256The amount of tokens to mint

_burn
​

Internal utility to burn tokens from a user's account.

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

Parameters

NameTypeDescription
fromaddressThe user to burn tokens from
iduint256The ERC1155 token id to mint
amountuint256The amount of tokens to burn

Events
​

TransferSingle
​

Emitted when only a single token is transferred.

event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 amount);

Parameters

NameTypeDescription
operatoraddressThe user who initiated the transfer
fromaddressThe user who sent the tokens
toaddressThe user who received the tokens
iduint256The ERC1155 token id
amountuint256The amount of tokens transferred

TransferBatch
​

Emitted when multiple tokens are transferred from one user to another.

event TransferBatch(
address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] amounts
);

Parameters

NameTypeDescription
operatoraddressThe user who initiated the transfer
fromaddressThe user who sent the tokens
toaddressThe user who received the tokens
idsuint256[]The ERC1155 token ids
amountsuint256[]The amounts of tokens transferred

ApprovalForAll
​

Emitted when the approval status of an operator to transfer all tokens on behalf of a user is modified.

event ApprovalForAll(address indexed owner, address indexed operator, bool approved);

Parameters

NameTypeDescription
owneraddressThe user who approved or disapproved operator to transfer their tokens
operatoraddressThe user who was approved or disapproved to transfer all tokens on behalf of owner
approvedboolWhether operator is approved or disapproved to transfer all tokens on behalf of owner

Errors
​

NotAuthorized
​

Emitted when a user attempts to transfer tokens they do not own nor are approved to transfer.

error NotAuthorized();

UnsafeRecipient
​

Emitted when an attempt is made to initiate a transfer to a contract recipient that fails to signal support for ERC1155.

error UnsafeRecipient();