EIPs Explained

ERC-4341 · Stagnant · ERC · 2021-10-01

ERC-4341: Ordered NFT Batch Standard

A multi-token interface that keeps the order of a batch of NFTs, so a sequence of tokens whose IDs encode Unicode characters can be sent and read back as a phrase.

What problem does it solve?

ERC-1155 batch transfers move a set of token IDs and amounts, but once the tokens land in a wallet the order in which they arrived is lost. For collectibles that is fine.

ERC-4341 targets a different use: tokens whose tokenId is a Unicode code point, such as a Chinese character or an emoji. In logographic languages a few characters carry a whole word or saying, and the order matters. The spec's example: IDs 38271 and 22478 decode to 长城 ("Great Wall"), while the reverse order decodes to 城长, a different word. The standard adds a way to send such a sequence and later retrieve it in the original order.

How it works

The interface looks like ERC-1155 (safeTransferFrom, safeBatchTransferFrom, balanceOf, balanceOfBatch, setApprovalForAll) plus three phrase functions:

Function Purpose
safePhraseTransferFrom(from, to, phrase, data) Transfer an ordered array of token IDs as one phrase
balanceOfPhrase(owner) How many phrases an address has received
retrievePhrase(owner, phraseId) Return the ordered ID array of one phrase

A phrase is stored as an array of unsigned integers in contract storage. It is a record of order only: creating it does not change any token balance, and a phrase itself cannot be transferred. Anyone can read it back and decode the IDs to characters.

The design builds on ERC-3754, which treats NFTs as plain units that can carry abstract meaning.

Sample code

Decoding a retrieved phrase into text (ethers v6):

import { Contract, JsonRpcProvider } from "ethers";

const provider = new JsonRpcProvider(process.env.RPC_URL);
const abi = [
  "function balanceOfPhrase(address owner) view returns (uint256)",
  "function retrievePhrase(address owner, uint256 phraseId) view returns (uint256[])",
];
const token = new Contract(process.env.TOKEN_ADDRESS!, abi, provider);

const owner = "0xYourAddress";
const count: bigint = await token.balanceOfPhrase(owner);
for (let i = 0n; i < count; i++) {
  const ids: bigint[] = await token.retrievePhrase(owner, i);
  const text = String.fromCodePoint(...ids.map(Number));
  console.log(i, text); // e.g. "长城" for [38271, 22478]
}

The phrase ID scheme (here assumed to be a 0-based index) is not fixed by the spec; check the implementation you are using.

Things to know

  • Status is Stagnant: the proposal has not advanced and has little adoption.
  • Storing phrases costs extra storage compared with plain ERC-1155.
  • The spec itself notes the idea suits logographic scripts and emojis; for alphabetic languages one token per letter is impractical.
  • The spec does not define how phrase IDs are assigned or whether a sender must hold all tokens in the phrase; those details live in the reference implementation.

#nft #multi-token #unicode #batch

Details

Authors
Simon Tian (@simontianx)
Status
Stagnant
Type
Standards Track / ERC
Created
2021-10-01

Machine-readable: Markdown · JSON