EIPs Explained

ERC-7738 · Draft · ERC · 2024-07-01

ERC-7738: Permissionless Script Registry

A permissionless on-chain registry where anyone can publish script URIs for any contract, so wallets can find client-side scripts even for contracts that never implemented ERC-5169.

What problem does it solve?

ERC-5169 lets a token contract point to client-side scripts (for example TokenScript) that wallets and viewers can run to give the token a richer interface. But the contract must implement scriptURI() itself, at deploy time or via an upgrade. Most existing contracts never did, and many are not upgradeable.

ERC-7738 moves the lookup out of the token and into a separate registry contract. Anyone can register scripts for any contract address, and wallets query the registry instead of the token. The intent is a singleton deployed at the same address on many chains, so no central server or gatekeeper is needed.

How it works

The registry exposes two functions and one event:

  • setScriptURI(contractAddress, string[] uris): anyone can call it. Entries are stored per (target contract, setter).
  • scriptURI(contractAddress): returns all registered URIs for that contract.
  • ScriptUpdate event: emitted on every update so wallets can refresh cached scripts.

Because writing is permissionless, ordering matters. The registry should return entries set by the target contract's ERC-173 owner() first; simple wallets just take the first URI. The registry should also support paging when there are many entries.

Trust is handled off-chain. A wallet fetching a script should verify its signature, ideally against the contract's owner(). If the contract is not Ownable, the spec suggests alternatives such as checking against the deployer key, a wallet-embedded keychain, or a governance-approved signer list.

Sample code

The interface from the spec:

// SPDX-License-Identifier: CC0-1.0
pragma solidity ^0.8.20;

interface IERC7738 {
    event ScriptUpdate(address indexed contractAddress, string[] newScriptURI);

    function scriptURI(address contractAddress) external view returns (string[] memory);
    function setScriptURI(address contractAddress, string[] memory scriptURIList) external;
}

A wallet looking up scripts for a token (ethers v6):

import { Contract, JsonRpcProvider } from "ethers";

const provider = new JsonRpcProvider(process.env.RPC_URL);
const registry = new Contract(REGISTRY_ADDRESS, [
  "function scriptURI(address) view returns (string[])",
], provider);

const uris: string[] = await registry.scriptURI(tokenAddress);
const preferred = uris[0]; // owner-set entries come first
// fetch(preferred), then verify the script's signature before running it

Things to know

  • Status: Draft.
  • Anyone can register a script for any contract, so a URI in the registry is not an endorsement. Never execute a script without verifying who signed it; on mainnet the spec advises caution when the signer cannot be authenticated.
  • The spec's simplified implementation emits ScriptUpdate with an extra msg.sender argument, which does not match the two-argument event in the interface. Check the event signature of the deployment you index.
  • The spec mentions a live deployment address; confirm it on each chain before relying on it.

#registry #scripts #tokenscript #wallet #metadata

Details

Authors
Victor Zhang (@zhangzhongnan928), James Brown (@JamesSmartCell)
Status
Draft
Type
Standards Track / ERC
Created
2024-07-01
Requires

Machine-readable: Markdown · JSON