Skip to content

Solidity API

SpanningERC1155

_Implementation of the basic standard multi-token. See https://eips.ethereum.org/EIPS/eip-1155 Originally based on code by Enjin: https://github.com/enjin/erc-1155

Available since v3.1._

balances_

mapping(uint256 => mapping(bytes32 => uint256)) balances_

operatorApprovals_

mapping(bytes32 => mapping(bytes32 => bool)) operatorApprovals_

uri_

string uri_

constructor

constructor(string uri, address delegate) public

_See {setURI}.

supportsInterface

function supportsInterface(bytes4 interfaceId) public view virtual returns (bool)

See {IERC165-supportsInterface}.

uri

function uri(uint256) public view virtual returns (string)

_See {IERC1155MetadataURI-uri}.

This implementation returns the same URI for all token types. It relies on the token type ID substitution mechanism https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].

Clients calling this function must replace the \{id\} substring with the actual token type ID._

balanceOf

function balanceOf(address accountLegacyAddress, uint256 id) public view virtual returns (uint256)

_See {IERC1155-balanceOf}.

Requirements:

  • accountLegacyAddress cannot be the zero address._

balanceOf

function balanceOf(bytes32 account, uint256 id) public view virtual returns (uint256)

Returns the amount of tokens of token type id owned by account.

NameTypeDescription
accountbytes32- Spanning Address to be queried
iduint256- Token type
NameTypeDescription
[0]uint256Token value of token type id for an account Requirements: - account cannot be the zero address.

balanceOfBatch

function balanceOfBatch(address[] accountsLegacyAddress, uint256[] ids) public view virtual returns (uint256[])

_See {IERC1155-balanceOfBatch}.

Requirements:

  • accounts and ids must have the same length._

balanceOfBatch

function balanceOfBatch(bytes32[] accounts, uint256[] ids) public view virtual returns (uint256[])

xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}.

NameTypeDescription
accountsbytes32[]- a batch of Spanning Address to be queried
idsuint256[]- a batch of Token type
NameTypeDescription
[0]uint256[]a batch of token value of token type ids for a batch of accounts Requirements: - accounts and ids must have the same length.

setApprovalForAll

function setApprovalForAll(address receiverLegacyAddress, bool approved) public virtual

See {IERC1155-setApprovalForAll}.

setApprovalForAll

function setApprovalForAll(bytes32 receiverAddress, bool approved) public virtual

See {IERC1155-setApprovalForAll}.

isApprovedForAll

function isApprovedForAll(address senderLegacyAddress, address receiverLegacyAddress) public view virtual returns (bool)

See {IERC1155-isApprovedForAll}.

isApprovedForAll

function isApprovedForAll(bytes32 senderAddress, bytes32 receiverAddress) public view virtual returns (bool)

See {IERC1155-isApprovedForAll}.

safeTransferFrom

function safeTransferFrom(address senderLegacyAddress, address receiverLegacyAddress, uint256 id, uint256 amount, bytes data) public virtual

See {IERC1155-safeTransferFrom}.

safeTransferFrom

function safeTransferFrom(bytes32 senderAddress, bytes32 receiverAddress, uint256 id, uint256 amount, bytes data) public virtual

See {IERC1155-safeTransferFrom}.

safeBatchTransferFrom

function safeBatchTransferFrom(address senderLegacyAddress, address receiverLegacyAddress, uint256[] ids, uint256[] amounts, bytes data) public virtual

See {IERC1155-safeBatchTransferFrom}.

safeBatchTransferFrom

function safeBatchTransferFrom(bytes32 senderAddress, bytes32 receiverAddress, uint256[] ids, uint256[] amounts, bytes data) public virtual

See {IERC1155-safeBatchTransferFrom}.

_safeTransferFrom

function _safeTransferFrom(bytes32 senderAddress, bytes32 receiverAddress, uint256 id, uint256 amount, bytes data) internal virtual

_safeBatchTransferFrom

function _safeBatchTransferFrom(bytes32 senderAddress, bytes32 receiverAddress, uint256[] ids, uint256[] amounts, bytes data) internal virtual

_setURI

function _setURI(string newuri) internal virtual

_Sets a new URI for all token types, by relying on the token type ID substitution mechanism https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP].

By this mechanism, any occurrence of the \{id\} substring in either the URI or any of the amounts in the JSON file at said URI will be replaced by clients with the token type ID.

For example, the https://token-cdn-domain/\{id\}.json URI would be interpreted by clients as https://token-cdn-domain/000000000000000000000000000000000000000000000000000000000004cce0.json for token type ID 0x4cce0.

See {uri}.

Because these URIs cannot be meaningfully represented by the {URI} event, this function emits no events._

_mint

function _mint(bytes32 receiverAddress, uint256 id, uint256 amount, bytes data) internal virtual

_Creates amount tokens of token type id, and assigns them to receiverAddress.

Emits a {TransferSingle} event.

Requirements:

  • receiverAddress cannot be the zero address.
  • If receiverAddress refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the acceptance magic value._

_mintBatch

function _mintBatch(bytes32 receiverAddress, uint256[] ids, uint256[] amounts, bytes data) internal virtual

_xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_mint}.

Requirements:

  • ids and amounts must have the same length.
  • If receiverAddress refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the acceptance magic value._

_burn

function _burn(bytes32 senderAddress, uint256 id, uint256 amount) internal virtual

_Destroys amount tokens of token type id from senderAddress

Requirements:

  • senderAddress cannot be the zero address.
  • senderAddress must have at least amount tokens of token type id._

_burnBatch

function _burnBatch(bytes32 senderAddress, uint256[] ids, uint256[] amounts) internal virtual

_xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_burn}.

Requirements:

  • ids and amounts must have the same length._

_setApprovalForAll

function _setApprovalForAll(bytes32 senderAddress, bytes32 receiverAddress, bool approved) internal virtual

_Approve receiverAddress to operate on all of senderAddress tokens

Emits a {ApprovalForAll} event._

_beforeTokenTransfer

function _beforeTokenTransfer(bytes32 operator, bytes32 senderAddress, bytes32 receiverAddress, uint256[] ids, uint256[] amounts, bytes data) internal virtual

_Hook that is called before any token transfer. This includes minting and burning, as well as batched variants.

The same hook is called on both single and batched variants. For single transfers, the length of the id and amount arrays will be 1.

Calling conditions (for each id and amount pair):

  • When senderAddress and receiverAddress are both non-zero, amount of senderAddress's tokens of token type id will be transferred to receiverAddress.
  • When senderAddress is zero, amount tokens of token type id will be minted for receiverAddress.
  • when receiverAddress is zero, amount of senderAddress's tokens of token type id will be burned.
  • senderAddress and receiverAddress are never both zero.
  • ids and amounts have the same, non-zero length.

To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]._

_afterTokenTransfer

function _afterTokenTransfer(bytes32 operator, bytes32 senderAddress, bytes32 receiverAddress, uint256[] ids, uint256[] amounts, bytes data) internal virtual

_Hook that is called after any token transfer. This includes minting and burning, as well as batched variants.

The same hook is called on both single and batched variants. For single transfers, the length of the id and amount arrays will be 1.

Calling conditions (for each id and amount pair):

  • When senderAddress and receiverAddress are both non-zero, amount of senderAddress's tokens of token type id will be transferred to receiverAddress.
  • When senderAddress is zero, amount tokens of token type id will be minted for receiverAddress.
  • when receiverAddress is zero, amount of senderAddress's tokens of token type id will be burned.
  • senderAddress and receiverAddress are never both zero.
  • ids and amounts have the same, non-zero length.

To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]._

_doSafeTransferAcceptanceCheck

function _doSafeTransferAcceptanceCheck(bytes32 operator, bytes32 senderAddress, bytes32 receiverAddress, uint256 id, uint256 amount, bytes data) private

_doSafeBatchTransferAcceptanceCheck

function _doSafeBatchTransferAcceptanceCheck(bytes32 operator, bytes32 senderAddress, bytes32 receiverAddress, uint256[] ids, uint256[] amounts, bytes data) private

_asSingletonArray

function _asSingletonArray(uint256 element) private pure returns (uint256[])