EIPs Explained

ERC-6909 · Final · ERC · 2023-04-19

ERC-6909: Minimal Multi-Token Interface

A lean multi-token standard: many token ids in one contract with ERC-20-style transfer, approve and allowance, but no mandatory callbacks or batch functions, and with per-id allowances plus operators.

What problem does it solve?

ERC-1155 lets one contract manage many token ids, but it carries baggage that many applications do not need:

  • Every transfer to a contract must call a receiver hook, and there is no way to opt out. That is extra gas and an extra external call (a reentrancy surface).
  • Batch transfer functions are mandatory, with one fixed ABI encoding.
  • Permissions are all-or-nothing: setApprovalForAll gives an operator unlimited control over every id. There is no per-id allowance.

ERC-6909 is a minimal alternative for protocols that track many fungible balances in one contract, such as AMM claim tokens or vault shares.

How it works

Balances are balanceOf(owner, id). The core interface mirrors ERC-20 with an extra id:

Function Purpose
transfer(receiver, id, amount) Move tokens from caller
transferFrom(sender, receiver, id, amount) Move on someone's behalf
approve(spender, id, amount) Allowance for one id
allowance(owner, spender, id) Remaining allowance
setOperator(spender, approved) Unlimited rights over all ids
isOperator(owner, spender) Operator status

Permission rules for transferFrom: the caller must be the sender, an operator, or have enough allowance. Allowance is decreased only when the caller is not an operator and the allowance is not infinite (type(uint256).max).

Events: Transfer(caller, sender, receiver, id, amount) (with zero address for mint and burn), Approval and OperatorSet. There are no callbacks and no batch methods; implementations can add their own batching if they want.

Optional extensions: metadata (name(id), symbol(id), decimals(id)), content URI (contractURI(), tokenURI(id)), and totalSupply(id).

The ERC-165 interface id is 0x0f632fb3.

Sample code

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract MiniERC6909 {
    event Transfer(address caller, address indexed sender, address indexed receiver, uint256 indexed id, uint256 amount);
    event OperatorSet(address indexed owner, address indexed spender, bool approved);
    event Approval(address indexed owner, address indexed spender, uint256 indexed id, uint256 amount);

    mapping(address => mapping(uint256 => uint256)) public balanceOf;
    mapping(address => mapping(address => mapping(uint256 => uint256))) public allowance;
    mapping(address => mapping(address => bool)) public isOperator;

    function transfer(address receiver, uint256 id, uint256 amount) public returns (bool) {
        balanceOf[msg.sender][id] -= amount;
        balanceOf[receiver][id] += amount;
        emit Transfer(msg.sender, msg.sender, receiver, id, amount);
        return true;
    }

    function transferFrom(address sender, address receiver, uint256 id, uint256 amount) public returns (bool) {
        if (msg.sender != sender && !isOperator[sender][msg.sender]) {
            uint256 allowed = allowance[sender][msg.sender][id];
            if (allowed != type(uint256).max) allowance[sender][msg.sender][id] = allowed - amount;
        }
        balanceOf[sender][id] -= amount;
        balanceOf[receiver][id] += amount;
        emit Transfer(msg.sender, sender, receiver, id, amount);
        return true;
    }

    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;
    }

    function setOperator(address spender, bool approved) public returns (bool) {
        isOperator[msg.sender][spender] = approved;
        emit OperatorSet(msg.sender, spender, approved);
        return true;
    }

    function supportsInterface(bytes4 i) public pure returns (bool) {
        return i == 0x01ffc9a7 || i == 0x0f632fb3;
    }
}

Things to know

  • Status: Final. Uniswap v4 uses ERC-6909 balances in its singleton pool manager, and libraries such as Solmate and Solady ship implementations.
  • Because there are no receiver hooks, tokens sent to a contract that cannot handle them are stuck. That is the same trade-off as ERC-20.
  • ERC-6909 is not backwards compatible with ERC-1155. Wallets, marketplaces and indexers need explicit support.
  • Operators get unlimited rights over every id, so treat setOperator like an infinite approval.

#token #multi-token #standard #defi #gas

Details

Authors
JT Riley (@jtriley2p), Dillon (@d1ll0n), Sara (@snreynolds), Vectorized (@Vectorized), Neodaoist (@neodaoist)
Status
Final
Type
Standards Track / ERC
Created
2023-04-19
Requires
Required by

Machine-readable: Markdown · JSON