{"eip":6047,"title":"ERC-721 Balance indexing via Transfer event","description":"Mandates emitting the Transfer event for ERC-721 NFTs during contract creation","authors":["Zainan Victor Zhou (@xinbenlv)"],"status":"Stagnant","type":"Standards Track","category":"ERC","created":"2022-11-26","requires":[721],"discussionsTo":"https://ethereum-magicians.org/t/eip-xxx-require-erc721-to-always-emit-transfer/11894","repo":"ERCs","label":"ERC-6047","officialUrl":"https://eips.ethereum.org/EIPS/eip-6047","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-6047.md","url":"https://eips.huatuo.xyz/eip-6047/","tldr":{"en":"Closes an ERC-721 loophole by requiring NFT contracts to emit Transfer events even for tokens minted inside the constructor, so indexers can track every token from logs alone.","ja":"コンストラクタ内でミントされたトークンについても Transfer イベントの emit を NFT コントラクトに求めることで、ERC-721 の抜け穴をふさぎ、インデクサーがログだけですべてのトークンを追跡できるようにする。","ko":"생성자 안에서 민팅된 토큰에 대해서도 NFT 컨트랙트가 Transfer 이벤트를 emit하도록 요구해 ERC-721의 허점을 메우고, 인덱서가 로그만으로 모든 토큰을 추적할 수 있게 한다.","zh":"通过要求 NFT 合约即使对在构造函数内铸造的代币也触发 Transfer 事件，堵住 ERC-721 的一个漏洞，使索引器仅凭日志就能跟踪每一个代币。"},"tags":["nft","erc721","events","indexing"],"explainers":{"en":{"lang":"en","tldr":"Closes an ERC-721 loophole by requiring NFT contracts to emit Transfer events even for tokens minted inside the constructor, so indexers can track every token from logs alone.","tags":["nft","erc721","events","indexing"],"related":[721,1155],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-6047/","markdown":"## What problem does it solve?\n\n[ERC-721](/eip-721/) says a `Transfer` event must be emitted for every mint (from `0x0`), transfer and burn (to `0x0`), **except during contract creation**. A contract can therefore mint tokens in its constructor without logging them.\n\nIndexers, marketplaces and wallets typically reconstruct who owns what by replaying `Transfer` logs. Tokens minted silently at deployment are invisible to them unless they add special-case logic. [ERC-1155](/eip-1155/) has no such exception, which is why its supply is easier to index.\n\nERC-6047 removes the exception for contracts that opt in.\n\n## How it works\n\nThe specification is two rules:\n\n1. A compliant contract must implement ERC-721.\n2. It must emit `Transfer` whenever a token is transferred, minted or burned, **including during contract creation**.\n\nNo new event is introduced. Reusing the existing `Transfer(address indexed from, address indexed to, uint256 indexed tokenId)` means existing indexers work without changes.\n\nEvery ERC-6047 contract is a valid ERC-721 contract; the reverse is not true.\n\n## Sample code\n\nMinting in the constructor while still logging each token:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract GenesisNFT {\n    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\n\n    mapping(uint256 =\u003e address) public ownerOf;\n    mapping(address =\u003e uint256) public balanceOf;\n\n    constructor(address[] memory recipients) {\n        for (uint256 id = 0; id \u003c recipients.length; id++) {\n            ownerOf[id] = recipients[id];\n            balanceOf[recipients[id]] += 1;\n            emit Transfer(address(0), recipients[id], id); // required by ERC-6047\n        }\n    }\n    // ... rest of ERC-721 omitted\n}\n```\n\nRebuilding ownership purely from logs (ethers v6):\n\n```ts\nimport { Contract, JsonRpcProvider } from \"ethers\";\n\nconst provider = new JsonRpcProvider(process.env.RPC_URL);\nconst nft = new Contract(process.env.NFT!, [\n  \"event Transfer(address indexed from, address indexed to, uint256 indexed tokenId)\",\n], provider);\n\nconst owners = new Map\u003cbigint, string\u003e();\nfor (const log of await nft.queryFilter(nft.filters.Transfer(), Number(process.env.DEPLOY_BLOCK))) {\n  const { to, tokenId } = (log as any).args;\n  owners.set(tokenId, to);\n}\n```\n\n## Things to know\n\n- Status is **Stagnant**: it is not an adopted requirement, and nothing marks a contract as compliant on-chain.\n- Popular libraries already emit `Transfer` from their internal `_mint`, so constructor mints using them normally produce logs anyway. The gap mainly affects hand-rolled or gas-optimised contracts that write storage directly.\n- Indexers should still start scanning from the deployment block (including the creation transaction) to catch constructor mints.\n- Emitting one event per token in a constructor costs gas; very large genesis mints may hit block gas limits.\n"},"ja":{"lang":"ja","tldr":"コンストラクタ内でミントされたトークンについても Transfer イベントの emit を NFT コントラクトに求めることで、ERC-721 の抜け穴をふさぎ、インデクサーがログだけですべてのトークンを追跡できるようにする。","tags":["nft","erc721","events","indexing"],"related":[721,1155],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-6047/","markdown":"## 何を解決するのか\n\n[ERC-721](/eip-721/) は、ミント（`0x0` から）、転送、burn（`0x0` へ）のたびに `Transfer` イベントを emit しなければならないとしていますが、**コントラクト作成中は例外**です。そのため、コントラクトはコンストラクタ内でログを残さずにトークンをミントできてしまいます。\n\nインデクサー、マーケットプレイス、ウォレットは、通常 `Transfer` ログをリプレイして誰が何を持っているかを再構築します。デプロイ時に黙ってミントされたトークンは、特別扱いのロジックを足さない限り、それらには見えません。[ERC-1155](/eip-1155/) にはそのような例外がないため、供給量のインデックス化がより簡単です。\n\nERC-6047 は、オプトインしたコントラクトについてこの例外を取り除きます。\n\n## 仕組み\n\n仕様は 2 つのルールです。\n\n1. 準拠するコントラクトは ERC-721 を実装しなければならない。\n2. トークンが転送、ミント、burn されるたびに、**コントラクト作成中を含めて** `Transfer` を emit しなければならない。\n\n新しいイベントは導入されません。既存の `Transfer(address indexed from, address indexed to, uint256 indexed tokenId)` を再利用するため、既存のインデクサーは変更なしで動作します。\n\nすべての ERC-6047 コントラクトは有効な ERC-721 コントラクトですが、その逆は成り立ちません。\n\n## サンプルコード\n\nコンストラクタ内でミントしつつ、各トークンをログに残す例:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract GenesisNFT {\n    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\n\n    mapping(uint256 =\u003e address) public ownerOf;\n    mapping(address =\u003e uint256) public balanceOf;\n\n    constructor(address[] memory recipients) {\n        for (uint256 id = 0; id \u003c recipients.length; id++) {\n            ownerOf[id] = recipients[id];\n            balanceOf[recipients[id]] += 1;\n            emit Transfer(address(0), recipients[id], id); // required by ERC-6047\n        }\n    }\n    // ... rest of ERC-721 omitted\n}\n```\n\nログだけから所有状況を再構築する（ethers v6）:\n\n```ts\nimport { Contract, JsonRpcProvider } from \"ethers\";\n\nconst provider = new JsonRpcProvider(process.env.RPC_URL);\nconst nft = new Contract(process.env.NFT!, [\n  \"event Transfer(address indexed from, address indexed to, uint256 indexed tokenId)\",\n], provider);\n\nconst owners = new Map\u003cbigint, string\u003e();\nfor (const log of await nft.queryFilter(nft.filters.Transfer(), Number(process.env.DEPLOY_BLOCK))) {\n  const { to, tokenId } = (log as any).args;\n  owners.set(tokenId, to);\n}\n```\n\n## 知っておくべきこと\n\n- ステータスは **Stagnant** です。採用された要件ではなく、コントラクトが準拠していることをオンチェーンで示す仕組みもありません。\n- 一般的なライブラリは内部の `_mint` からすでに `Transfer` を emit しているため、それらを使ったコンストラクタ内のミントは通常ログを生成します。この抜け穴が主に影響するのは、ストレージに直接書き込む手書きやガス最適化されたコントラクトです。\n- コンストラクタ内のミントを捉えるため、インデクサーは引き続きデプロイブロック（作成トランザクションを含む）からスキャンを始めるべきです。\n- コンストラクタでトークンごとに 1 つのイベントを emit するにはガスがかかります。非常に大規模なジェネシスミントはブロックのガスリミットに達する可能性があります。\n"},"ko":{"lang":"ko","tldr":"생성자 안에서 민팅된 토큰에 대해서도 NFT 컨트랙트가 Transfer 이벤트를 emit하도록 요구해 ERC-721의 허점을 메우고, 인덱서가 로그만으로 모든 토큰을 추적할 수 있게 한다.","tags":["nft","erc721","events","indexing"],"related":[721,1155],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-6047/","markdown":"## 어떤 문제를 해결하나요?\n\n[ERC-721](/eip-721/)은 민팅(`0x0`에서), 전송, 소각(`0x0`으로)마다 `Transfer` 이벤트를 emit해야 한다고 하지만, **컨트랙트 생성 중에는 예외**입니다. 그래서 컨트랙트는 생성자에서 로그를 남기지 않고 토큰을 민팅할 수 있습니다.\n\n인덱서, 마켓플레이스, 지갑은 보통 `Transfer` 로그를 재생해 누가 무엇을 소유하는지 재구성합니다. 배포 시 조용히 민팅된 토큰은 특별 처리 로직을 추가하지 않는 한 이들에게 보이지 않습니다. [ERC-1155](/eip-1155/)에는 이런 예외가 없어서 공급량을 인덱싱하기가 더 쉽습니다.\n\nERC-6047은 옵트인한 컨트랙트에 대해 이 예외를 없앱니다.\n\n## 어떻게 동작하나요?\n\n스펙은 두 가지 규칙입니다.\n\n1. 준수하는 컨트랙트는 ERC-721을 구현해야 한다.\n2. 토큰이 전송, 민팅, 소각될 때마다 **컨트랙트 생성 중에도** `Transfer`를 emit해야 한다.\n\n새 이벤트는 도입되지 않습니다. 기존 `Transfer(address indexed from, address indexed to, uint256 indexed tokenId)`를 재사용하므로 기존 인덱서는 변경 없이 동작합니다.\n\n모든 ERC-6047 컨트랙트는 유효한 ERC-721 컨트랙트이지만, 그 반대는 성립하지 않습니다.\n\n## 샘플 코드\n\n생성자에서 민팅하면서도 각 토큰을 로그로 남기는 예:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract GenesisNFT {\n    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\n\n    mapping(uint256 =\u003e address) public ownerOf;\n    mapping(address =\u003e uint256) public balanceOf;\n\n    constructor(address[] memory recipients) {\n        for (uint256 id = 0; id \u003c recipients.length; id++) {\n            ownerOf[id] = recipients[id];\n            balanceOf[recipients[id]] += 1;\n            emit Transfer(address(0), recipients[id], id); // required by ERC-6047\n        }\n    }\n    // ... rest of ERC-721 omitted\n}\n```\n\n로그만으로 소유 관계 재구성하기(ethers v6):\n\n```ts\nimport { Contract, JsonRpcProvider } from \"ethers\";\n\nconst provider = new JsonRpcProvider(process.env.RPC_URL);\nconst nft = new Contract(process.env.NFT!, [\n  \"event Transfer(address indexed from, address indexed to, uint256 indexed tokenId)\",\n], provider);\n\nconst owners = new Map\u003cbigint, string\u003e();\nfor (const log of await nft.queryFilter(nft.filters.Transfer(), Number(process.env.DEPLOY_BLOCK))) {\n  const { to, tokenId } = (log as any).args;\n  owners.set(tokenId, to);\n}\n```\n\n## 알아둘 점\n\n- 상태는 **Stagnant**입니다. 채택된 요구 사항이 아니며, 컨트랙트가 준수한다는 것을 온체인에서 표시하는 방법도 없습니다.\n- 인기 있는 라이브러리는 이미 내부 `_mint`에서 `Transfer`를 emit하므로, 이를 사용한 생성자 민팅은 보통 어차피 로그를 만듭니다. 이 허점은 주로 스토리지에 직접 쓰는 직접 작성했거나 가스 최적화된 컨트랙트에 영향을 줍니다.\n- 인덱서는 생성자 민팅을 잡기 위해 여전히 배포 블록(생성 트랜잭션 포함)부터 스캔을 시작해야 합니다.\n- 생성자에서 토큰마다 이벤트 하나를 emit하면 가스가 듭니다. 매우 큰 제네시스 민팅은 블록 가스 한도에 걸릴 수 있습니다.\n"},"zh":{"lang":"zh","tldr":"通过要求 NFT 合约即使对在构造函数内铸造的代币也触发 Transfer 事件，堵住 ERC-721 的一个漏洞，使索引器仅凭日志就能跟踪每一个代币。","tags":["nft","erc721","events","indexing"],"related":[721,1155],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-6047/","markdown":"## 它解决什么问题？\n\n[ERC-721](/eip-721/) 规定每次铸造（来自 `0x0`）、转让和销毁（转到 `0x0`）都必须触发 `Transfer` 事件，**合约创建期间除外**。因此合约可以在构造函数中铸造代币而不记录日志。\n\n索引器、市场和钱包通常通过重放 `Transfer` 日志来重建谁拥有什么。部署时悄悄铸造的代币对它们不可见，除非它们增加特殊处理逻辑。[ERC-1155](/eip-1155/) 没有这样的例外，因此它的供应量更容易索引。\n\nERC-6047 为选择采用的合约取消了这一例外。\n\n## 它如何运作\n\n规范只有两条规则：\n\n1. 合规的合约必须实现 ERC-721。\n2. 每当代币被转让、铸造或销毁时，必须触发 `Transfer`，**包括合约创建期间**。\n\n没有引入新事件。复用现有的 `Transfer(address indexed from, address indexed to, uint256 indexed tokenId)`，意味着现有索引器无需改动即可工作。\n\n每个 ERC-6047 合约都是有效的 ERC-721 合约；反之则不然。\n\n## 示例代码\n\n在构造函数中铸造，同时仍为每个代币记录日志：\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract GenesisNFT {\n    event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);\n\n    mapping(uint256 =\u003e address) public ownerOf;\n    mapping(address =\u003e uint256) public balanceOf;\n\n    constructor(address[] memory recipients) {\n        for (uint256 id = 0; id \u003c recipients.length; id++) {\n            ownerOf[id] = recipients[id];\n            balanceOf[recipients[id]] += 1;\n            emit Transfer(address(0), recipients[id], id); // required by ERC-6047\n        }\n    }\n    // ... rest of ERC-721 omitted\n}\n```\n\n仅凭日志重建所有权（ethers v6）：\n\n```ts\nimport { Contract, JsonRpcProvider } from \"ethers\";\n\nconst provider = new JsonRpcProvider(process.env.RPC_URL);\nconst nft = new Contract(process.env.NFT!, [\n  \"event Transfer(address indexed from, address indexed to, uint256 indexed tokenId)\",\n], provider);\n\nconst owners = new Map\u003cbigint, string\u003e();\nfor (const log of await nft.queryFilter(nft.filters.Transfer(), Number(process.env.DEPLOY_BLOCK))) {\n  const { to, tokenId } = (log as any).args;\n  owners.set(tokenId, to);\n}\n```\n\n## 需要注意\n\n- 状态为 **Stagnant**：它不是被采纳的要求，链上也没有任何标记表明某个合约合规。\n- 流行的库已经在其内部的 `_mint` 中触发 `Transfer`，因此使用它们在构造函数中铸造通常本来就会产生日志。这个缺口主要影响手写的或经过 gas 优化、直接写存储的合约。\n- 索引器仍应从部署区块（包括创建交易）开始扫描，以捕获构造函数中的铸造。\n- 在构造函数中为每个代币触发一个事件会消耗 gas；规模非常大的创世铸造可能触及区块 gas 上限。\n"}}}
