EIPs Explained

ERC-7656 · Final · ERC · 2024-03-15

ERC-7656: Generalized Contract-Linked Services

A factory standard for deploying deterministic minimal-proxy 'services' linked to any NFT or smart account, so you can add features such as recovery, staking or permissions without changing the original contract.

What problem does it solve?

Token-bound accounts (ERC-6551) showed that you can attach a contract to an NFT at a predictable address, owned by whoever owns the token. But that design assumes the attached contract is an account, and it only links to NFTs.

Many useful add-ons are not accounts: a social-recovery module for a wallet, a staking or rental vault for an NFT, a dynamic-metadata service, compliance logic for a real-world-asset token. ERC-7656 generalizes the idea. One factory can deploy any service contract, linked either to a specific token ID or to a contract with no ID (such as an ERC-4337 smart account), without touching the linked contract's code.

How it works

IERC7656Factory (interface ID 0x9e23230a) has two functions with the same arguments:

  • create(implementation, salt, chainId, mode, linkedContract, linkedId) — deploys the service and emits Created.
  • compute(...) — returns the address it would have, so services can be referenced before deployment.

Each service is an ERC-1167 minimal proxy pointing at implementation, with the link data appended to its bytecode (183 bytes total): salt, chainId, mode, linkedContract, linkedId. The factory stores nothing; the address is fully determined by these inputs.

The bytes12 mode says how to interpret the link:

Mode Value Use
LINKED_ID 0x…00 Linked to a token ID, e.g. an ERC-721 NFT; compatible with token-bound accounts
NO_LINKED_ID 0x…01 Linked to a contract without an ID, e.g. a smart account; linkedId should be 0

The remaining mode bytes are reserved for future linking rules. Services should implement IERC7656Service.linkedData() (interface ID 0x7e110a1d), check ownership through the linked contract, and verify chainId == block.chainid.

Sample code

Predicting and deploying a service linked to an NFT (ethers v6):

import { Contract, ZeroHash } from "ethers";

const factoryAbi = [
  "function compute(address,bytes32,uint256,bytes12,address,uint256) view returns (address)",
  "function create(address,bytes32,uint256,bytes12,address,uint256) returns (address)",
];
const factory = new Contract(factoryAddress, factoryAbi, signer);

const LINKED_ID = "0x000000000000000000000000";
const { chainId } = await signer.provider!.getNetwork();
const args = [serviceImpl, ZeroHash, chainId, LINKED_ID, nftContract, 1234n] as const;

const predicted = await factory.compute(...args);
console.log("service will live at", predicted);
await (await factory.create(...args)).wait();

A service's owner check, as in the spec's example:

function owner() public view returns (address) {
    (uint256 chainId, , address token, uint256 id) = linkedData();
    if (chainId != block.chainid) return address(0);
    return IERC721(token).ownerOf(id);
}

Things to know

  • Status is Final.
  • The factory does not vet implementations. Anyone can link a malicious service to your NFT or account address; only trust services whose implementation you have reviewed.
  • A seller could change a linked service's settings just before a sale; marketplaces may need lock periods.
  • An NFT whose linked wallet holds that same NFT creates an ownership cycle that can lock assets.
  • Upgradeable implementations reintroduce trust in the upgrader; the spec recommends timelocks or multisig control.

#factory #nft #account-abstraction #proxy #extensions

Details

Authors
Francesco Sullo (@sullof)
Status
Final
Type
Standards Track / ERC
Created
2024-03-15
Requires
Required by

Machine-readable: Markdown · JSON