OpenZeppelin ContractsAPI ReferenceToken

ERC6909

Smart contract ERC6909 utilities and implementations

This set of interfaces and contracts are all related to the ERC-6909 Minimal Multi-Token Interface.

The ERC consists of four interfaces which fulfill different roles--the interfaces are as follows:

  1. IERC6909: Base interface for a vanilla ERC6909 token.
  2. IERC6909ContentURI: Extends the base interface and adds content URI (contract and token level) functionality.
  3. IERC6909Metadata: Extends the base interface and adds metadata functionality, which exposes a name, symbol, and decimals for each token id.
  4. IERC6909TokenSupply: Extends the base interface and adds total supply functionality for each token id.

Implementations are provided for each of the 4 interfaces defined in the ERC.

Core

ERC6909

Extensions

ERC6909ContentURI

ERC6909Metadata

ERC6909TokenSupply

import "@openzeppelin/contracts/token/ERC6909/draft-ERC6909.sol";

Implementation of ERC-6909. See https://eips.ethereum.org/EIPS/eip-6909

supportsInterface(bytes4 interfaceId) → bool

public

#

Returns true if this contract implements the interface defined by interfaceId. See the corresponding ERC section to learn more about how these ids are created.

This function call must use less than 30 000 gas.

balanceOf(address owner, uint256 id) → uint256

public

#

Returns the amount of tokens of type id owned by owner.

allowance(address owner, address spender, uint256 id) → uint256

public

#

Returns the amount of tokens of type id that spender is allowed to spend on behalf of owner.

NOTE: Does not include operator allowances.

isOperator(address owner, address spender) → bool

public

#

Returns true if spender is set as an operator for owner.

approve(address spender, uint256 id, uint256 amount) → bool

public

#

Sets an approval to spender for amount of tokens of type id from the caller's tokens. An amount of type(uint256).max signifies an unlimited approval.

Must return true.

setOperator(address spender, bool approved) → bool

public

#

Grants or revokes unlimited transfer permission of any token id to spender for the caller's tokens.

Must return true.

transfer(address receiver, uint256 id, uint256 amount) → bool

public

#

Transfers amount of token type id from the caller's account to receiver.

Must return true.

transferFrom(address sender, address receiver, uint256 id, uint256 amount) → bool

public

#

Transfers amount of token type id from sender to receiver.

Must return true.

_mint(address to, uint256 id, uint256 amount)

internal

#

Creates amount of token id and assigns them to account, by transferring it from address(0). Relies on the _update mechanism.

Emits a IERC6909.Transfer event with from set to the zero address.

NOTE: This function is not virtual, ERC1155._update should be overridden instead.

_transfer(address from, address to, uint256 id, uint256 amount)

internal

#

Moves amount of token id from from to to without checking for approvals. This function verifies that neither the sender nor the receiver are address(0), which means it cannot mint or burn tokens. Relies on the _update mechanism.

Emits a IERC6909.Transfer event.

NOTE: This function is not virtual, ERC1155._update should be overridden instead.

_burn(address from, uint256 id, uint256 amount)

internal

#

Destroys a amount of token id from account. Relies on the _update mechanism.

Emits a IERC6909.Transfer event with to set to the zero address.

NOTE: This function is not virtual, ERC1155._update should be overridden instead

_update(address from, address to, uint256 id, uint256 amount)

internal

#

Transfers amount of token id from from to to, or alternatively mints (or burns) if from (or to) is the zero address. All customizations to transfers, mints, and burns should be done by overriding this function.

Emits a IERC6909.Transfer event.

_approve(address owner, address spender, uint256 id, uint256 amount)

internal

#

Sets amount as the allowance of spender over the owner's id tokens.

This internal function is equivalent to approve, and can be used to e.g. set automatic allowances for certain subsystems, etc.

Emits an IERC6909.Approval event.

Requirements:

  • owner cannot be the zero address.
  • spender cannot be the zero address.

_setOperator(address owner, address spender, bool approved)

internal

#

Approve spender to operate on all of owner's tokens

This internal function is equivalent to setOperator, and can be used to e.g. set automatic allowances for certain subsystems, etc.

Emits an IERC6909.OperatorSet event.

Requirements:

  • owner cannot be the zero address.
  • spender cannot be the zero address.

_spendAllowance(address owner, address spender, uint256 id, uint256 amount)

internal

#

Updates owner's allowance for spender based on spent amount.

Does not update the allowance value in case of infinite allowance. Revert if not enough allowance is available.

Does not emit an IERC6909.Approval event.

ERC6909InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 id)

error

#

ERC6909InsufficientAllowance(address spender, uint256 allowance, uint256 needed, uint256 id)

error

#

ERC6909InvalidApprover(address approver)

error

#

ERC6909InvalidReceiver(address receiver)

error

#

ERC6909InvalidSender(address sender)

error

#

ERC6909InvalidSpender(address spender)

error

#
import "@openzeppelin/contracts/token/ERC6909/extensions/draft-ERC6909ContentURI.sol";

Implementation of the Content URI extension defined in ERC6909.

contractURI() → string

public

#

Returns URI for the contract.

tokenURI(uint256 id) → string

public

#

Returns the URI for the token of type id.

_setContractURI(string newContractURI)

internal

#

_setTokenURI(uint256 id, string newTokenURI)

internal

#

Sets the IERC6909ContentURI.tokenURI for a given token of type id.

Emits a IERC1155.URI event.

ContractURIUpdated()

event

#

Event emitted when the contract URI is changed. See ERC-7572 for details.

URI(string value, uint256 indexed id)

event

#
import "@openzeppelin/contracts/token/ERC6909/extensions/draft-ERC6909Metadata.sol";

Implementation of the Metadata extension defined in ERC6909. Exposes the name, symbol, and decimals of each token id.

name(uint256 id) → string

public

#

Returns the name of the token of type id.

symbol(uint256 id) → string

public

#

Returns the ticker symbol of the token of type id.

decimals(uint256 id) → uint8

public

#

Returns the number of decimals for the token of type id.

_setName(uint256 id, string newName)

internal

#

Sets the name for a given token of type id.

Emits an ERC6909Metadata.ERC6909NameUpdated event.

_setSymbol(uint256 id, string newSymbol)

internal

#

Sets the symbol for a given token of type id.

Emits an ERC6909Metadata.ERC6909SymbolUpdated event.

_setDecimals(uint256 id, uint8 newDecimals)

internal

#

Sets the decimals for a given token of type id.

Emits an ERC6909Metadata.ERC6909DecimalsUpdated event.

ERC6909NameUpdated(uint256 indexed id, string newName)

event

#

The name of the token of type id was updated to newName.

ERC6909SymbolUpdated(uint256 indexed id, string newSymbol)

event

#

The symbol for the token of type id was updated to newSymbol.

ERC6909DecimalsUpdated(uint256 indexed id, uint8 newDecimals)

event

#

The decimals value for token of type id was updated to newDecimals.

import "@openzeppelin/contracts/token/ERC6909/extensions/draft-ERC6909TokenSupply.sol";

Implementation of the Token Supply extension defined in ERC6909. Tracks the total supply of each token id individually.

totalSupply(uint256 id) → uint256

public

#

Returns the total supply of the token of type id.

_update(address from, address to, uint256 id, uint256 amount)

internal

#

Override the _update function to update the total supply of each token id as necessary.