EIPs Explained

ERC-2309 · Final · ERC · 2019-10-08

ERC-2309: ERC-721 Consecutive Transfer Extension

An optional ERC-721 event, ConsecutiveTransfer, that reports the mint, transfer or burn of a whole range of token IDs in one log, so huge NFT batches don't need one Transfer event per token.

What problem does it solve?

ERC-721 says a Transfer event must be emitted whenever ownership of any NFT changes. Indexers, marketplaces and block explorers rely on those events to work out who owns what.

That rule makes large batches expensive. A contract can use clever data structures to mint a million tokens in one transaction, but emitting a million Transfer events in a loop would run out of gas. ERC-2309 gives such contracts a single, standard event that describes a whole range of consecutive token IDs at once.

How it works

ERC-2309 defines one event and nothing else. It does not say how you implement batch minting or transfers, only how you announce them:

event ConsecutiveTransfer(
    uint256 indexed fromTokenId,
    uint256 toTokenId,
    address indexed fromAddress,
    address indexed toAddress
);

The rules:

  • fromTokenId to toTokenId must be a consecutive range of IDs.
  • Minting uses fromAddress == address(0); burning uses toAddress == address(0).
  • fromTokenId, fromAddress and toAddress are indexed; toTokenId is not and lives in the log data.
  • The caller must own every token in the range or be an approved operator.
  • When you emit ConsecutiveTransfer for a set of tokens, you must not also emit Transfer for them. A contract may still use plain Transfer for ordinary single-token moves.

The event works for a single token too: ConsecutiveTransfer(1, 1, address(0), alice) mints token 1.

Sample code

Emitting the event when minting a batch (bookkeeping simplified for illustration):

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

contract BatchNFT {
    event ConsecutiveTransfer(
        uint256 indexed fromTokenId,
        uint256 toTokenId,
        address indexed fromAddress,
        address indexed toAddress
    );

    uint256 public nextId = 1;
    // A real contract stores ownership compactly, e.g. one entry per batch.
    mapping(uint256 => address) internal batchOwner; // keyed by first id of batch

    function mintBatch(address to, uint256 quantity) external {
        require(quantity > 0, "qty");
        uint256 first = nextId;
        uint256 last = first + quantity - 1;
        batchOwner[first] = to;
        nextId = last + 1;
        emit ConsecutiveTransfer(first, last, address(0), to); // one log for the whole range
    }
}

Listening from an indexer (ethers v6):

import { Contract, JsonRpcProvider } from "ethers";

const provider = new JsonRpcProvider(process.env.RPC_URL);
const nft = new Contract(nftAddress, [
  "event ConsecutiveTransfer(uint256 indexed fromTokenId, uint256 toTokenId, address indexed fromAddress, address indexed toAddress)",
], provider);

nft.on("ConsecutiveTransfer", (fromId, toId, from, to) => {
  console.log(`tokens ${fromId}..${toId}: ${from} -> ${to}`);
});

Things to know

  • Status is Final, but support is optional. An indexer that only listens for Transfer will miss ownership changes reported through ConsecutiveTransfer, so tools should watch both.
  • OpenZeppelin's ERC721Consecutive extension uses this event for batch minting during construction.
  • The spec positions it against ERC-1155, which batches well for semi-fungible items but still logs per-ID data; ERC-2309 is aimed at minting very large numbers of unique tokens.
  • Detecting that a contract is an NFT is still done through ERC-165 supportsInterface; the event itself has no interface ID.

#nft #erc721 #events #batch #minting

Details

Authors
Sean Papanikolas (@pizzarob)
Status
Final
Type
Standards Track / ERC
Created
2019-10-08
Requires

Machine-readable: Markdown · JSON