Introduction
Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.
I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.
I also build and publish a variety of tools, libraries, and open-source projects.
This article covers ERC6909, a proposal that addresses security concerns and usability limitations associated with ERC1155.
This article translates, summarizes, and adds explanations to the specification linked below.
ERC6909 was at the Draft stage as of September 3, 2023, when the original article was written.
Overview
This proposal defines a multi-token contract as a simpler alternative to the ERC-1155 Multi-Token Standard.
See the following resource for more on ERC1155.
Motivation
The ERC1155 standard includes several additional features. For example, when a recipient is a contract, it must implement a callback that returns a specified value.
Under ERC1155, when tokens are transferred or batch-transferred to a contract, the recipient contract must implement a callback that returns the specified value. The callback allows the receiving contract to perform predefined operations when it receives tokens.
Specifically, when tokens are transferred, a particular function (the callback) defined in the recipient contract is executed. Because this function runs when the contract receives tokens, it needs to return the specified value. This makes token transfers and operations explicit and allows custom logic in recipient contracts.
However, because the callback calls external code in the recipient contract, gas consumption and execution time require careful consideration. In some situations, callback versioning and compatibility between the sending and receiving contracts also need attention.
Consider the following code example.
// ERC-1155 token contract
contract MyERC1155Token {
// Mapping that tracks balances by token ID
mapping(address => mapping(uint256 => uint256)) private balances;
// Callback function for token transfers
function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes memory _data)
public returns (bytes4)
{
// Implement code that returns the required value here
// Perform the necessary processing and set the return value
// Example: return a particular value
return bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"));
}
// Token transfer function
function safeTransfer(address _to, uint256 _id, uint256 _amount, bytes memory _data)
public
{
// Deduct tokens from the balance
balances[msg.sender][_id] -= _amount;
// Call the recipient account's onERC1155Received callback
bytes4 response = IERC1155Receiver(_to).onERC1155Received(msg.sender, address(this), _id, _amount, _data);
require(response == bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)")), "Invalid response");
// Credit tokens to the recipient account
balances[_to][_id] += _amount;
}
}
// ERC-1155 recipient interface
interface IERC1155Receiver {
function onERC1155Received(address _operator, address _from, uint256 _id, uint256 _value, bytes memory _data)
external returns(bytes4);
}The code above is a simplified illustration of an ERC1155 token transfer and the receiving contract's callback. The onERC1155Received function is invoked when tokens are transferred to a recipient contract.
Custom logic in the callback can perform processing and return the expected value.
The transfer succeeds when the recipient contract handles the callback correctly.
However, actual implementations require attention to security and optimization; this illustrative code is not production-ready. The ERC1155 standard has complex aspects relating to token operations and needs to be implemented carefully.
The specification also includes batch calls for operating on multiple tokens at once. In addition, its operator approval scheme grants an approved operator unlimited permission across all token IDs in the contract.
This is how token approval works under ERC1155. When one account is authorized as an operator to transfer tokens on behalf of another account, it has unlimited transfer authority over all of that owner's token IDs in the contract. Although convenient for handling multiple tokens, this broad authorization can raise security concerns.
The proposed alternative deliberately drops backward compatibility where necessary.
The original discussion contrasts ERC1155 with the proposed alternative: backward compatibility can be retained where it is needed when introducing a new version. Where maintaining compatibility is unnecessary, it may be deliberately dropped to introduce new features or improvements. This can facilitate changes in newer designs.
Batch calls, methods for increasing and decreasing allowances, and other user-experience features are deliberately omitted from the proposed specification to keep its external interface minimal.
In the proposed ERC6909 alternative to ERC1155, batch calls that operate on multiple tokens and methods for increasing or decreasing allowances are among the convenience features omitted. This is a choice intended to keep the external interface simple. It leaves room for implementations to provide these features differently and adapt to different environments and requirements.
The ERC1155 specification requires callbacks when token transfers or batch transfers target a contract. This behavior may be desirable in some cases. However, standards such as ERC721 offer both ordinary and safe transfer methods, and a callback may not be invoked depending on the method used. Requiring multiple callback functions and return values affects both the token contract and the recipient contract in terms of runtime performance and code size.
Batch transfers are useful, but this proposal omits them from the core standard so implementations can handle transfers flexibly. For example, alternative ABI encodings can optimize calldata size or runtime performance in environments with high gas costs.
The hybrid allowance and operator scheme supports fine-grained authorization while accounting for scalability. An allowance authorizes an external account to transfer tokens on behalf of a user for a particular token ID, whereas an operator has full transfer authority over all of that user's token IDs.
The proposed hybrid allowance and operator scheme in ERC6909, unlike ERC1155's operator-only approach, combines granular authorization with scalability.
-
Roles of allowances and operators
- Allowance
- An allowance authorizes an external account to transfer tokens belonging to a user for a specific token ID.
- Users can therefore delegate control over a portion of their token holdings to another account.
- Operator
- An operator has full transfer authority over all token IDs belonging to the user who granted authorization.
- This allows the operator to manage all the user's tokens.
- Allowance
-
Characteristics of the hybrid allowance and operator scheme
- Granularity and flexibility
- Users can set allowances for individual token IDs, allowing a specified account to transfer only the tokens it needs.
- This provides fine-grained control over tokens.
- Scalability
- An operator can manage all of a user's tokens, maintaining scalability even when the user holds many token types.
- Common operator authorization across multiple token IDs makes management more efficient; batch operations themselves are not part of the core interface.
- Granularity and flexibility
Specification
Definitions
- infinite
- Refers to the maximum value of the integer type
uint256. uint256is a256-bit unsigned integer type with a maximum value of 2 raised to the power of 256 minus 1, used to represent very large numbers.
- Refers to the maximum value of the integer type
- caller
- Refers to the account that initiated the operation in the current execution context.
- For example, in a token transfer, the account performing the operation is the
caller.
- spender
- Refers to authority granted to an account to transfer tokens on behalf of another account.
- Specifically, a token owner grants authorization to another account so that it can transfer the owner's tokens.
- operator
- Refers to an account that has unlimited transfer authority over all token IDs belonging to another account.
- The account can operate on tokens without obtaining separate approval for each transfer, so owners may grant this role to accounts they trust.
- mint
- Refers to creating new tokens.
- This operation increases token supply, usually through a dedicated method or transaction.
- burn
- Refers to removing existing tokens.
- This operation decreases token supply, usually through a dedicated method or transaction.
Functions
totalSupply
- name: totalSupply
type: function
stateMutability: view
inputs:
- name: id
type: uint256
outputs:
- name: amount
type: uint256Overview Retrieves the total quantity of tokens issued for a specified token ID.
It must equal the sum of balanceOf across all holders of that token ID.
Arguments
id- Specified token ID.
Return value
amount- Total supply of the specified token ID.
balanceOf
- name: balanceOf
type: function
stateMutability: view
inputs:
- name: owner
type: address
- name: id
type: uint256
outputs:
- name: amount
type: uint256Overview Retrieves the balance of a specified token ID held by a particular address.
Arguments
owner- Address whose token balance is being queried.
id- Specified token ID.
Return value
amount- Balance of the specified token ID held by the specified address.
allowance
- name: allowance
type: function
stateMutability: view
inputs:
- name: owner
type: address
- name: spender
type: address
- name: id
type: uint256
outputs:
- name: amount
type: uint256Overview Retrieves the quantity of a particular token ID that a spender is authorized to transfer on behalf of the owner.
Arguments
owner- Token owner's address.
spender- Address whose authorization to spend the owner's tokens is being queried.
id- Specified token ID.
Return value
amount- Total quantity of tokens that the
spenderis authorized to transfer.
- Total quantity of tokens that the
isOperator
- name: isOperator
type: function
stateMutability: view
inputs:
- name: owner
type: address
- name: spender
type: address
outputs:
- name: status
type: boolOverview Checks whether a particular address has been approved as an operator for a token holder.
Arguments
owner- Token owner's address.
spender- Address whose operator authorization for the token holder is being queried.
Return value
status- A
boolindicating whether the address is approved.
- A
transfer
- name: transfer
type: function
stateMutability: nonpayable
inputs:
- name: receiver
type: address
- name: id
type: uint256
- name: amount
type: uint256
outputs:
- name: success
type: boolOverview
Transfers a specified quantity (amount) of a specified token ID from the caller to the designated address (receiver).
Details
Transfers the specified quantity (amount) of the token ID from the caller's account to the designated address (receiver).
If the caller's balance is insufficient for the transfer, the operation fails.
On success, a Transfer event is logged and true is returned.
Arguments
receiver- Address receiving the tokens.
id- Token ID to transfer.
amount- Quantity to transfer.
Return value
successtrueif the transfer succeeds.
transferFrom
- name: transferFrom
type: function
stateMutability: nonpayable
inputs:
- name: sender
type: address
- name: receiver
type: address
- name: id
type: uint256
- name: amount
type: uint256
outputs:
- name: success
type: boolOverview
Allows the caller to transfer a specified quantity (amount) of a specified token ID from a sender (sender) to a recipient (receiver).
Details
The transfer can proceed when the caller is the sender itself, an authorized operator, or a spender with sufficient allowance for the token ID, including unlimited allowance.
On success, a Transfer event is logged and true is returned.
The operation fails if the sender's balance is insufficient or the caller lacks the required authorization. An approved operator does not need a separate allowance; a non-operator spender does.
Arguments
sender- Address sending the tokens.
receiver- Address receiving the tokens.
id- ID of the token to transfer.
amount- Quantity to transfer.
Return value
successtrueif the transfer succeeds.
approve
- name: approve
type: function
stateMutability: nonpayable
inputs:
- name: spender
type: address
- name: id
type: uint256
- name: amount
type: uint256
outputs:
- name: success
type: boolOverview
Authorizes a specified address (spender) to transfer a specified quantity (amount) of a particular token ID on behalf of the caller.
Details
Sets the allowance for the specified address (spender) and token ID.
The allowance lets the spender transfer up to the specified quantity of tokens on behalf of the caller.
When the allowance is set, an Approval event is logged and true is returned.
Arguments
spender- Address authorized to transfer tokens (
spender).
- Address authorized to transfer tokens (
id- Token ID for which the
allowanceis set.
- Token ID for which the
amount- Quantity of tokens to authorize.
Return value
successtrueif the setting succeeds.
setOperator
function setOperator(address spender, bool approved) nonpayable returns (bool success)Overview
Lets the caller grant or revoke unlimited transfer authority for any token ID to a specified address (spender).
Details
Grants or revokes unlimited token transfer authority (operator authorization) for the specified address (spender).
When operator authorization is set, an OperatorSet event is logged and true is returned.
Arguments
spender- Address whose operator authorization is being set.
approvedtrueto grant operator authorization orfalseto revoke it.
Return value
successtrueif the setting succeeds.
Events
The following sections explain the individual events and their parameters.
Transfer
- name: Transfer
type: event
inputs:
- name: sender
indexed: true
type: address
- name: receiver
indexed: true
type: address
- name: id
indexed: true
type: uint256
- name: amount
indexed: false
type: uint256Overview An event emitted when a quantity of a specified token ID is transferred from one account to another.
Details When tokens are minted, the sender address is recorded as the zero address. When tokens are burned, the recipient address is recorded as the zero address.
Parameters
sender- Address that sent the tokens.
receiver- Address that received the tokens.
id- Token ID transferred.
amount- Quantity transferred.
OperatorSet
- name: OperatorSet
type: event
inputs:
- name: owner
indexed: true
type: address
- name: spender
indexed: true
type: address
- name: approved
indexed: false
type: boolOverview
An event emitted when an owner sets the operator authorization status of a specified address (spender).
Parameters
owner- Address of the owner who set the operator authorization.
spender- Address whose operator authorization was set.
approved- Operator authorization status (
trueorfalse).
- Operator authorization status (
Approval
- name: Approval
type: event
inputs:
- name: owner
indexed: true
type: address
- name: spender
indexed: true
type: address
- name: id
indexed: true
type: uint256
- name: amount
indexed: false
type: uint256Overview
An event emitted when an owner sets the allowance for a specified address (spender) and token ID.
Parameters
owner- Address of the owner who set the
allowance.
- Address of the owner who set the
spender- Address for which the
allowancewas set.
- Address for which the
id- Token ID for which the
allowancewas set.
- Token ID for which the
amount- Token quantity authorized by the
allowance.
- Token quantity authorized by the
Additional considerations
Granular approvals
Under the ERC1155 operator model, an account can designate another account as an operator, granting authority to transfer any quantity of any token ID on behalf of the owner.
However, this is not always the appropriate level of authorization.
In contrast, the ERC20 allowance model lets an account explicitly specify how many tokens another account may spend on behalf of the owner.
This standard implements both models and includes a token ID when specifying an allowance.
This allows a limited approval for a particular token ID, unlimited approval for a particular token ID, or unlimited approval across all token IDs.
When an account is designated as an operator, care must be taken not to decrease its allowance when it transfers tokens on the owner's behalf.
Removal of batch operations
Batch operations are convenient, but the proposal argues that they should be considered independently according to the circumstances rather than included in the core standard.
This allows different choices of calldata layout.
It is particularly useful for applications such as rollups, which commit calldata to global storage.
Removal of mandatory callbacks
Callbacks may be used in multi-token contracts, but they are not mandatory under this standard. This reduces external calls and additional checks, improving gas efficiency.
Removal of the "safe" prefix
The naming of safeTransfer and safeTransferFrom can be misleading, especially in the context of ERC1155 and ERC721.
These methods require an external call to a recipient account that contains code.
Control flow passes to an arbitrary contract, which must meet the required conditions.
By removing mandatory callbacks and the word safe from method names, the proposal improves the predictability of control flow by default.
Potential misunderstandings about the naming of safeTransfer and safeTransferFrom
Consider a token transfer in a game.
Suppose player A wants to transfer tokens to player B.
In this case, the illustrative safeTransfer method is called.
Although the name suggests a safe transfer, control flow may actually pass to player B's recipient contract, depending on how it handles the required conditions.
Example 1: A Sieve of Eratosthenes contract
Imagine that the recipient contract implements the Sieve of Eratosthenes algorithm. When the illustrative safeTransfer method is called, player B's contract performs mathematical calculations to determine whether a particular condition is satisfied.
If the condition is satisfied, the tokens are transferred; otherwise, the transaction fails.
https://algo-method.com/descriptions/64
Solution: Improve control-flow safety
To avoid these misunderstandings, the proposal uses clearer method names instead of names such as safeTransfer and safeTransferFrom.
Because control flow can pass to external contracts, it also proposes removing the mandatory external callback requirement to improve control-flow safety.
This makes execution more predictable by default, helping developers write code with predictable behavior. It does not itself guarantee that a recipient can recover tokens sent without a callback.
Method naming and external callback requirements therefore affect control-flow safety and the predictability of development.
Interface ID
An interface ID is a unique identifier for a particular interface across contracts.
In the version of the specification discussed in this article, the value 0xb2e69f8a identifies the relevant interface.
Metadata
name
Name of the contract.
- name: name
type: function
stateMutability: view
inputs: []
outputs:
- name: name
type: stringsymbol
Symbol of the contract.
- name: symbol
type: function
stateMutability: view
inputs: []
outputs:
- name: symbol
type: stringdecimals
Number of decimal places for the token.
- name: decimals
type: function
stateMutability: view
inputs:
- name: id
type: uint256
outputs:
- name: amount
type: uint8Metadata URI extension
tokenURI
URI for the token ID. The client substitutes the {id} portion of the returned URI string.
- name: tokenURI
type: function
stateMutability: view
inputs:
- name: id
type: uint256
outputs:
- name: uri
type: stringMetadata structure
The metadata specification follows the ERC721 JSON schema. The client substitutes occurrences of {id} in the returned URI string.
{
"title": "Asset Metadata",
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Identifies the token"
},
"description": {
"type": "string",
"description": "Describes the token"
},
"image": {
"type": "string",
"description": "A URI pointing to an image resource."
}
}
}Backward compatibility
Introducing the new specification may break backward compatibility with ERC1155. This is because some methods are removed. However, compatibility can be provided by implementing wrappers for the existing ERC20, ERC721, and ERC1155 standards.
Reference implementation
// SPDX-License-Identifier: CC0-1.0
pragma solidity 0.8.19;
/// @title ERC6909 Multi-Token Reference Implementation
/// @author jtriley.eth
contract ERC6909 {
/// @dev Thrown when owner balance for id is insufficient.
/// @param owner The address of the owner.
/// @param id The id of the token.
error InsufficientBalance(address owner, uint256 id);
/// @dev Thrown when spender allowance for id is insufficient.
/// @param spender The address of the spender.
/// @param id The id of the token.
error InsufficientPermission(address spender, uint256 id);
/// @notice The event emitted when a transfer occurs.
/// @param sender The address of the sender.
/// @param receiver The address of the receiver.
/// @param id The id of the token.
/// @param amount The amount of the token.
event Transfer(address indexed sender, address indexed receiver, uint256 indexed id, uint256 amount);
/// @notice The event emitted when an operator is set.
/// @param owner The address of the owner.
/// @param spender The address of the spender.
/// @param approved The approval status.
event OperatorSet(address indexed owner, address indexed spender, bool approved);
/// @notice The event emitted when an approval occurs.
/// @param owner The address of the owner.
/// @param spender The address of the spender.
/// @param id The id of the token.
/// @param amount The amount of the token.
event Approval(address indexed owner, address indexed spender, uint256 indexed id, uint256 amount);
/// @notice The total supply of each id.
mapping(uint256 id => uint256 amount) public totalSupply;
/// @notice Owner balance of an id.
mapping(address owner => mapping(uint256 id => uint256 amount)) public balanceOf;
/// @notice Spender allowance of an id.
mapping(address owner => mapping(address spender => mapping(uint256 id => uint256 amount))) public allowance;
/// @notice Checks if a spender is approved by an owner as an operator.
mapping(address owner => mapping(address spender => bool)) public isOperator;
/// @notice Transfers an amount of an id from the caller to a receiver.
/// @param receiver The address of the receiver.
/// @param id The id of the token.
/// @param amount The amount of the token.
function transfer(address receiver, uint256 id, uint256 amount) public returns (bool) {
if (balanceOf[msg.sender][id] < amount) revert InsufficientBalance(msg.sender, id);
balanceOf[msg.sender][id] -= amount;
balanceOf[receiver][id] += amount;
emit Transfer(msg.sender, receiver, id, amount);
return true;
}
/// @notice Transfers an amount of an id from a sender to a receiver.
/// @param sender The address of the sender.
/// @param receiver The address of the receiver.
/// @param id The id of the token.
/// @param amount The amount of the token.
function transferFrom(address sender, address receiver, uint256 id, uint256 amount) public returns (bool) {
if (sender != msg.sender && !isOperator[sender][msg.sender]) {
uint256 senderAllowance = allowance[sender][msg.sender][id];
if (senderAllowance < amount) revert InsufficientPermission(msg.sender, id);
if (senderAllowance != type(uint256).max) {
allowance[sender][msg.sender][id] = senderAllowance - amount;
}
}
if (balanceOf[sender][id] < amount) revert InsufficientBalance(sender, id);
balanceOf[sender][id] -= amount;
balanceOf[receiver][id] += amount;
emit Transfer(sender, receiver, id, amount);
return true;
}
/// @notice Approves an amount of an id to a spender.
/// @param spender The address of the spender.
/// @param id The id of the token.
/// @param amount The amount of the token.
function approve(address spender, uint256 id, uint256 amount) public returns (bool) {
allowance[msg.sender][spender][id] = amount;
emit Approval(msg.sender, spender, id, amount);
return true;
}
/// @notice Sets or removes a spender as an operator for the caller.
/// @param spender The address of the spender.
/// @param approved The approval status.
function setOperator(address spender, bool approved) public returns (bool) {
isOperator[msg.sender][spender] = approved;
emit OperatorSet(msg.sender, spender, approved);
return true;
}
/// @notice Checks if a contract implements an interface.
/// @param interfaceId The interface identifier, as specified in ERC-165.
/// @return supported True if the contract implements `interfaceId`.
function supportsInterface(bytes4 interfaceId) public pure returns (bool supported) {
return interfaceId == 0xb2e69f8a || interfaceId == 0x01ffc9a7;
}
function _mint(address receiver, uint256 id, uint256 amount) internal {
// WARNING: important safety checks should precede calls to this method.
balanceOf[receiver][id] += amount;
totalSupply[id] += amount;
emit Transfer(address(0), receiver, id, amount);
}
function _burn(address sender, uint256 id, uint256 amount) internal {
// WARNING: important safety checks should precede calls to this method.
balanceOf[sender][id] -= amount;
totalSupply[id] -= amount;
emit Transfer(sender, address(0), id, amount);
}
}Security considerations
The delegated authorization scheme includes both the allowance model and the operator model.
The following explains the security considerations associated with these models and their interaction.
- Security considerations for the allowance model:
In the allowance model, a particular account is delegated permission to transfer tokens. As long as the allowance remains valid, that account can spend up to the authorized amount at any time, subject to the owner's balance. For example, if a token owner authorizes another account to transfer a specified quantity of tokens, that account can transfer up to its remaining allowance until the authorization is revoked.
- Security considerations for the operator model:
In the operator model, a token owner can grant another account authority to transfer their tokens across token IDs. An approved operator can transfer tokens on behalf of the owner, facilitating efficient token management.
- Security considerations when combining both delegated authorization models:
Under the transferFrom method, an approved operator is not constrained by a per-token allowance.
An address with unlimited allowance must not have its allowance reduced when transferring tokens; a spender relying on a finite allowance must have that allowance reduced by the quantity transferred.
However, a spender with both operator authorization and finite allowance can introduce ambiguity in how the two models interact.
If operator authorization takes precedence, the allowance is not decreased when the address is an operator. If allowance takes precedence instead, additional conditional checks may be required to prevent allowance underflow.
The following code examples illustrate this issue. The two contracts ERC6909OperatorPrecedence and ERC6909AllowancePrecedence demonstrate operator precedence and allowance precedence, respectively. Appropriate conditional checks and error handling are necessary to prevent allowance underflow.
contract ERC6909OperatorPrecedence {
// -- snip --
function transferFrom(address sender, address receiver, uint256 id, uint256 amount) public {
// check if `isOperator` first
if (msg.sender != sender && !isOperator[sender][msg.sender]) {
require(allowance[sender][msg.sender][id] >= amount, "insufficient allowance");
allowance[sender][msg.sender][id] -= amount;
}
// -- snip --
}
}
contract ERC6909AllowancePrecedence {
// -- snip --
function transferFrom(address sender, address receiver, uint256 id, uint256 amount) public {
// check if allowance is sufficient first
if (msg.sender != sender && allowance[sender][msg.sender][id] < amount) {
require(isOperator[sender][msg.sender], "insufficient allowance");
}
// ERROR: when allowance is insufficient, this panics due to arithmetic underflow, regardless of
// whether the caller has operator permissions.
allowance[sender][msg.sender][id] -= amount;
// -- snip
}
}Citation
Joshua Trujillo (@jtriley-eth), "ERC-6909: Minimal Multi-Token Interface [DRAFT]," Ethereum Improvement Proposals, no. 6909, April 2023. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-6909.
Conclusion
This article covered ERC6909, a proposed multi-token standard that offers more granular approvals than ERC1155. The Japanese source's conclusion refers to ERC5216, although the title, specification link, and body concern ERC6909. I hope this explanation was helpful.
If you have questions, feel free to contact me via Twitter DM:

