Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ERC6909

Inherits: Context, ERC165, IERC6909

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

State Variables

_balances

mapping(address owner => mapping(uint256 id => uint256)) private _balances;

_operatorApprovals

mapping(address owner => mapping(address operator => bool)) private _operatorApprovals;

_allowances

mapping(address owner => mapping(address spender => mapping(uint256 id => uint256))) private _allowances;

Functions

supportsInterface

Query if a contract implements an interface

Interface identification is specified in ERC-165. This function uses less than 30,000 gas.

function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool);

Parameters

NameTypeDescription
interfaceIdbytes4

Returns

NameTypeDescription
<none>booltrue if the contract implements interfaceID and interfaceID is not 0xffffffff, false otherwise

balanceOf

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

function balanceOf(address owner, uint256 id) public view virtual override returns (uint256);

allowance

Returns the amount of tokens of type id that spender is allowed to spend on behalf of owner. NOTE: Does not include operator allowances.

function allowance(address owner, address spender, uint256 id) public view virtual override returns (uint256);

isOperator

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

function isOperator(address owner, address spender) public view virtual override returns (bool);

approve

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.

function approve(address spender, uint256 id, uint256 amount) public virtual override returns (bool);

setOperator

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

function setOperator(address spender, bool approved) public virtual override returns (bool);

transfer

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

function transfer(address receiver, uint256 id, uint256 amount) public virtual override returns (bool);

transferFrom

Transfers amount of token type id from sender to receiver. Must return true.

function transferFrom(address sender, address receiver, uint256 id, uint256 amount)
    public
    virtual
    override
    returns (bool);

_mint

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. NOTE: This function is not virtual, {_update} should be overridden instead.

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

_transfer

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. NOTE: This function is not virtual, {_update} should be overridden instead.

function _transfer(address from, address to, uint256 id, uint256 amount) internal;

_burn

Destroys a amount of token id from account. Relies on the _update mechanism. Emits a {Transfer} event with to set to the zero address. NOTE: This function is not virtual, {_update} should be overridden instead

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

_update

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.

function _update(address from, address to, uint256 id, uint256 amount) internal virtual;

_approve

*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.*
function _approve(address owner, address spender, uint256 id, uint256 amount) internal virtual;

_setOperator

*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.*
function _setOperator(address owner, address spender, bool approved) internal virtual;

_spendAllowance

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 {Approval} event.

function _spendAllowance(address owner, address spender, uint256 id, uint256 amount) internal virtual;

Errors

ERC6909InsufficientBalance

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

ERC6909InsufficientAllowance

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

ERC6909InvalidApprover

error ERC6909InvalidApprover(address approver);

ERC6909InvalidReceiver

error ERC6909InvalidReceiver(address receiver);

ERC6909InvalidSender

error ERC6909InvalidSender(address sender);

ERC6909InvalidSpender

error ERC6909InvalidSpender(address spender);