Keyboard shortcuts

Press or to navigate between chapters

Press ? to show this help

Press Esc to hide this help

InternalTrait

Fully qualified path: openzeppelin_token::erc1155::erc1155::ERC1155Component::InternalTrait

pub trait InternalTrait<
    TContractState,
    +HasComponent<TContractState>,
    impl SRC5: HasComponent<TContractState>,
    impl Hooks: ERC1155HooksTrait<TContractState>,
    +Drop<TContractState>,
>

Trait functions

initializer

Initializes the contract by setting the base_uri for all tokens, and registering the supported interfaces. This should only be used inside the contract’s constructor.

WARNING: Most ERC1155 contracts expose the IERC1155MetadataURI interface which is what this initializer is meant to support. If the contract DOES NOT expose the IERC1155MetadataURI interface, meaning the token does not have a URI, the contract must instead use initializer_no_metadata in the constructor. Failure to abide by these instructions can lead to unexpected issues especially with UIs.

Fully qualified path: openzeppelin_token::erc1155::erc1155::ERC1155Component::InternalTrait::initializer

fn initializer(ref self: ComponentState<TContractState>, base_uri: ByteArray)

initializer_no_metadata

Initializes the contract with no metadata by registering only the IERC1155 interface.

WARNING: This initializer should ONLY be used during construction in the very specific instance when the contract does NOT expose the IERC1155MetadataURI interface. Initializing a contract with this initializer means that tokens will not have a URI.

Fully qualified path: openzeppelin_token::erc1155::erc1155::ERC1155Component::InternalTrait::initializer_no_metadata

fn initializer_no_metadata(ref self: ComponentState<TContractState>)

mint_with_acceptance_check

Creates a value amount of tokens of type token_id, and assigns them to to.

Requirements:

  • to cannot be the zero address.
  • If to refers to a smart contract, it must implement IERC1155Receiver::on_ERC1155_received and return the acceptance magic value.

Emits a TransferSingle event.

Fully qualified path: openzeppelin_token::erc1155::erc1155::ERC1155Component::InternalTrait::mint_with_acceptance_check

fn mint_with_acceptance_check(
    ref self: ComponentState<TContractState>,
    to: ContractAddress,
    token_id: u256,
    value: u256,
    data: Span<felt252>,
)

batch_mint_with_acceptance_check

Batched version of mint_with_acceptance_check.

Requirements:

  • to cannot be the zero address.
  • token_ids and values must have the same length.
  • If to refers to a smart contract, it must implement IERC1155Receiver::on_ERC1155_batch_received and return the acceptance magic value.

Emits a TransferBatch event.

Fully qualified path: openzeppelin_token::erc1155::erc1155::ERC1155Component::InternalTrait::batch_mint_with_acceptance_check

fn batch_mint_with_acceptance_check(
    ref self: ComponentState<TContractState>,
    to: ContractAddress,
    token_ids: Span<u256>,
    values: Span<u256>,
    data: Span<felt252>,
)

burn

Destroys a value amount of tokens of type token_id from from.

Requirements:

  • from cannot be the zero address.
  • from must have at least value amount of tokens of type token_id.

Emits a TransferSingle event.

Fully qualified path: openzeppelin_token::erc1155::erc1155::ERC1155Component::InternalTrait::burn

fn burn(
    ref self: ComponentState<TContractState>, from: ContractAddress, token_id: u256, value: u256,
)

batch_burn

Batched version of burn.

Requirements:

  • from cannot be the zero address.
  • from must have at least value amount of tokens of type token_id.
  • token_ids and values must have the same length.

Emits a TransferBatch event.

Fully qualified path: openzeppelin_token::erc1155::erc1155::ERC1155Component::InternalTrait::batch_burn

fn batch_burn(
    ref self: ComponentState<TContractState>,
    from: ContractAddress,
    token_ids: Span<u256>,
    values: Span<u256>,
)

update_with_acceptance_check

Version of update that performs the token acceptance check by calling IERC1155Receiver::onERC1155Received or IERC1155Receiver::onERC1155BatchReceived if the receiver is not recognized as an account.

Requirements:

  • to is either an account contract or supports the IERC1155Receiver interface.
  • token_ids and values must have the same length.

Emits a TransferSingle event if the arrays contain one element, and TransferBatch otherwise.

Fully qualified path: openzeppelin_token::erc1155::erc1155::ERC1155Component::InternalTrait::update_with_acceptance_check

fn update_with_acceptance_check(
    ref self: ComponentState<TContractState>,
    from: ContractAddress,
    to: ContractAddress,
    token_ids: Span<u256>,
    values: Span<u256>,
    data: Span<felt252>,
)

update

Transfers a value amount of tokens of type id from from to to. Will mint (or burn) if from (or to) is the zero address.

Requirements:

  • token_ids and values must have the same length.

Emits a TransferSingle event if the arrays contain one element, and TransferBatch otherwise.

NOTE: This function can be extended using the ERC1155HooksTrait, to add functionality before and/or after the transfer, mint, or burn.

NOTE: The ERC1155 acceptance check is not performed in this function. See update_with_acceptance_check instead.

Fully qualified path: openzeppelin_token::erc1155::erc1155::ERC1155Component::InternalTrait::update

fn update(
    ref self: ComponentState<TContractState>,
    from: ContractAddress,
    to: ContractAddress,
    token_ids: Span<u256>,
    values: Span<u256>,
)

_set_base_uri

Sets a new URI for all token types, by relying on the token type ID substitution mechanism defined in the ERC1155 standard. See https://eips.ethereum.org/EIPS/eip-1155#metadata.

By this mechanism, any occurrence of the \{id\} substring in either the URI or any of the values 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.

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

Fully qualified path: openzeppelin_token::erc1155::erc1155::ERC1155Component::InternalTrait::_set_base_uri

fn _set_base_uri(ref self: ComponentState<TContractState>, base_uri: ByteArray)