EIPs Explained

ERC-8121 · Draft · ERC · 2025-12-12

ERC-8121: Cross-Chain Function Calls via Hooks

Defines a self-describing "hook" value that names a function, its arguments, return type and a chain-qualified contract, so metadata stored on one chain can point clients to a trusted contract on another chain to resolve.

What problem does it solve?

Contracts often store metadata as key/value records (a token's description, an agent's credentials, a name's avatar). Sometimes the authoritative data lives elsewhere: a Proof-of-Personhood or KYC credential issued by a dedicated registry, perhaps on another chain. There was no standard way to store "go call this function on that contract on that chain" as a plain value, in a form both machines and humans (or AI agents reading a markdown file) can understand.

ERC-8121 defines such a value, a hook. Because the target is spelled out, a client can first decide whether it trusts the target contract before resolving anything.

How it works

A hook has five parts:

Part Example
functionSelector (optional checksum) 0xc41a360a
functionSignature "getOwner(uint256)"
functionCall (human-readable, with values) "getOwner(42)"
returnType "(address)"
target (ERC-7930 interoperable address = chain + contract) 0x0001000001011412…

It can be stored two ways:

  • Bytes: ABI-encoded behind a 4-byte hook selector: 0x037f43ed for hook(bytes4,string,string,string,bytes) (with selector) or 0x6113bfa3 for hook(string,string,string,bytes) (without).
  • String: literal text such as hook("getOwner(uint256)", "getOwner(42)", "(address)", 0x…).

To resolve a hook, a client detects it (by prefix), checks the selector against keccak256(functionSignature) if one is present, decodes the target's chain and address, checks the target is trusted, parses the call arguments, enables ERC-3668 CCIP-Read, calls the function on the target chain and decodes the result with returnType. Hooks can also describe writes, in which case the client signs and sends a transaction instead.

Clients are expected to know in advance which metadata keys may hold hooks, just as they know to look for "image" or "description".

Sample code

Detecting and decoding a bytes-format hook (ethers v6):

import { AbiCoder, dataSlice, id, getAddress, toNumber } from "ethers";

const WITH_SEL = "0x037f43ed";
const NO_SEL = "0x6113bfa3";
const coder = AbiCoder.defaultAbiCoder();

function decodeHook(value: string) {
  const prefix = value.slice(0, 10).toLowerCase();
  const body = dataSlice(value, 4);
  if (prefix === WITH_SEL) {
    const [sel, sig, call, ret, target] = coder.decode(["bytes4", "string", "string", "string", "bytes"], body);
    if (id(sig).slice(0, 10) !== sel.toLowerCase()) throw new Error("selector mismatch");
    return { sig, call, ret, target };
  }
  if (prefix === NO_SEL) {
    const [sig, call, ret, target] = coder.decode(["string", "string", "string", "bytes"], body);
    return { sig, call, ret, target };
  }
  return null; // not a hook: treat as a plain value
}

// ERC-7930, EVM case: version(2) chainType(2) refLen(1) chainRef addrLen(1) address
function decodeEvmTarget(target: string) {
  const refLen = toNumber(dataSlice(target, 4, 5));
  const chainId = toNumber(dataSlice(target, 5, 5 + refLen));
  const address = getAddress(dataSlice(target, 6 + refLen, 26 + refLen));
  return { chainId, address };
}

Things to know

  • Status is Draft.
  • Resolving a hook means calling an arbitrary contract the record points to. Clients should keep an allowlist (or use a trusted registry) of targets and refuse untrusted ones.
  • Limit recursion: a hook may resolve to another hook. The spec suggests a depth limit of 3–5.
  • Clients unaware of hooks simply return the encoded hook as the raw value, so adoption is backwards compatible.
  • One example in the spec annotates getContractMetadata(string) with selector 0x1837de7f; the actual keccak selector is 0x9e574b14 (as used in its string example). Always compute selectors yourself.

#cross-chain #metadata #ccip-read #interoperability

Details

Authors
Prem Makeig (@nxt3d)
Status
Draft
Type
Standards Track / ERC
Created
2025-12-12
Requires

Machine-readable: Markdown · JSON