ERC-6909
This document is better viewed at https://docs.openzeppelin.com/contracts/api/token/erc6909 |
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:
-
IERC6909
: Base interface for a vanilla ERC6909 token. -
IERC6909ContentURI
: Extends the base interface and adds content URI (contract and token level) functionality. -
IERC6909Metadata
: Extends the base interface and adds metadata functionality, which exposes a name, symbol, and decimals for each token id. -
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
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
.
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 transfer
event with from
set to the zero address.
This function is not virtual, _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 transfer
event.
This function is not virtual, _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 transfer
event with to
set to the zero address.
This function is not virtual, _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 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 {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 {OperatorSet} event.
Requirements:
-
owner
cannot be the zero address. -
spender
cannot be the zero address.
Extensions
ERC6909ContentURI
import "@openzeppelin/contracts/token/ERC6909/extensions/draft-ERC6909ContentURI.sol";
Implementation of the Content URI extension defined in ERC6909.
_setContractURI(string newContractURI)
internal
Sets the contractURI
for the contract.
Emits a ContractURIUpdated
event.
_setTokenURI(uint256 id, string newTokenURI)
internal
Sets the tokenURI
for a given token of type id
.
Emits a URI
event.
ContractURIUpdated()
event
Event emitted when the contract URI is changed. See ERC-7572 for details.
URI(string value, uint256 indexed id)
event
See IERC1155.URI
ERC6909Metadata
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.
_setName(uint256 id, string newName)
internal
Sets the name
for a given token of type id
.
Emits an ERC6909NameUpdated
event.
_setSymbol(uint256 id, string newSymbol)
internal
Sets the symbol
for a given token of type id
.
Emits an ERC6909SymbolUpdated
event.
_setDecimals(uint256 id, uint8 newDecimals)
internal
Sets the decimals
for a given token of type id
.
Emits an ERC6909DecimalsUpdated
event.
ERC6909NameUpdated(uint256 indexed id, string newName)
event
The name of the token of type id
was updated to newName
.