ERC-7884 · Draft · ERC · 2025-01-23
ERC-7884: Operation Router
A write-side companion to CCIP-Read: a contract tells clients, via a reverting view call, whether an update should go to an L2 contract or to an off-chain gateway authenticated with an EIP-712 signature.
What problem does it solve?
ERC-3668 (CCIP-Read) gave contracts a standard way to say "the data you want to read lives somewhere else". Many systems, ENS resolvers in particular, now keep their records on an L2 or in an off-chain database. But there was no matching standard for writes: when a user wants to update a record, the client had no generic way to learn where the update should be sent.
The Operation Router lets an L1 contract act as a signpost for write operations. A client asks the contract "where should this call go?" and gets a machine-readable answer: a specific contract on a specific chain, or an HTTP gateway that accepts signed requests.
How it works
The L1 contract implements one view function:
function getOperationHandler(bytes calldata encodedFunction) external view;
The client passes the ABI-encoded call it wants to make (for example setText(node, key, value)). The function never returns normally; it always reverts with one of three custom errors:
| Revert | Meaning |
|---|---|
OperationHandledOnchain(chainId, contractAddress) |
Send the same calldata as a transaction to contractAddress on chainId (L1 or an L2) |
OperationHandledOffchain(DomainData, url, MessageData) |
Sign the request with EIP-712 and POST it to url |
FunctionNotSupported() |
This selector is not routed |
For the off-chain case, DomainData is the EIP-712 domain (name, version, chainId, verifyingContract) and MessageData bundles the original calldata, the sender and an expirationTimestamp. The gateway URL follows the CCIP-Read /{sender}/{data}.json convention, so a server can behave like a contract, while the EIP-712 signature proves the user authorised the change.
Because routing is decided per encoded call, a multicall that touches several destinations cannot be routed in one go; the client must route each inner call separately.
Sample code
Router contract and a client loop (viem-style, as in the spec):
contract ProfileRouter {
error OperationHandledOnchain(uint256 chainId, address contractAddress);
error FunctionNotSupported();
address constant L2_RESOLVER = address(0); // set to your L2 contract
function getOperationHandler(bytes calldata encodedFunction) external view {
bytes4 selector = bytes4(encodedFunction[:4]);
if (selector == bytes4(keccak256("setAddr(bytes32,address)"))) {
revert OperationHandledOnchain(10, L2_RESOLVER);
}
revert FunctionNotSupported();
}
}
try {
await client.readContract({ address: router, abi, functionName: "getOperationHandler",
args: [encodeFunctionData(call)] });
} catch (err) {
const e = decodeErrorResult({ abi, data: getRevertData(err) });
if (e.errorName === "OperationHandledOnchain") {
const [chainId, target] = e.args;
await walletOn(Number(chainId)).writeContract({ ...call, address: target });
} else if (e.errorName === "OperationHandledOffchain") {
const [domain, url, message] = e.args;
const sig = await signer.signTypedData({ domain, types, primaryType: "Message", message });
await fetch(url, { method: "POST", body: JSON.stringify({ message, sig }) });
}
}
Things to know
- Status: Draft. Error names and the message format may still change.
- Using reverts to return data mirrors CCIP-Read's
OffchainLookuppattern; clients must decode revert data rather than return values. - Off-chain gateways are trusted infrastructure: the spec asks them to verify EIP-712 signatures, enforce access control, handle concurrent updates, rate-limit and use HTTPS.
- The
expirationTimestampinMessageDatalimits how long a signed off-chain request stays valid.