ERC-7412 · Draft · ERC · 2023-07-26
ERC-7412: On-Demand Off-Chain Data Retrieval
Lets a contract ask for fresh off-chain data (prices, cross-chain reads) by reverting with a standard error; the client fetches signed data and prepends a verification call in the same multicall, so the user still signs just one transaction.
What problem does it solve?
DeFi protocols on L2s and L3s need price feeds and data from other chains, but oracle networks cannot afford to keep pushing every feed to every chain all the time. A "pull" model is cheaper: bring the signed data on-chain only when a transaction actually needs it.
ERC-3668 (CCIP Read) already uses a revert to signal "I need off-chain data", but its callback design gets awkward when nested calls each need different data. ERC-7412 offers a simpler pattern built on multicalls.
How it works
- A contract that needs data it does not have (or whose cached copy is stale) reverts with:
error OracleDataRequired(address oracleContract, bytes oracleQuery, uint256 feeRequired). The format oforacleQueryis defined by the oracle, e.g. chain id + contract + calldata, or a ticker + timestamp. - The client (wallet or app SDK) sees this error while simulating the transaction. It looks up the
oracleId()oforacleContract, finds a gateway for that oracle network (like resolving an RPC from a chain id), and fetches signed data. - The client builds a multicall:
fulfillOracleQuery(signedData)first, then the original call. It simulates again and repeats until no more errors appear. - On-chain,
fulfillOracleQueryverifies the signatures and stores the result, so the original call can now read it.
The oracle contract implements:
oracleId(): abytes32identifying the oracle network.fulfillOracleQuery(bytes signedOffchainData)(payable). If it charges a fee, it reverts withFeeRequired(uint amount)until enoughmsg.value(in wei) is sent. Excess payment need not be refunded.
An optional Errors(bytes[] errors) lets a contract report several missing data items at once.
Atomic batching needs suitable infrastructure: ERC-4337 smart accounts can do it natively, and EOAs can use ERC-2771 forwarding. A plain multicall contract only works for calls that do not depend on msg.sender.
Sample code
Consumer contract and client loop (simplified; the verify step is the oracle's job):
interface IERC7412 {
function oracleId() external view returns (bytes32);
function fulfillOracleQuery(bytes calldata signedOffchainData) external payable;
}
error OracleDataRequired(address oracleContract, bytes oracleQuery, uint256 feeRequired);
contract PriceUser {
address public oracle;
mapping(bytes32 => uint256) public price; // filled by the oracle contract in a real setup
mapping(bytes32 => uint256) public updatedAt;
function quote(bytes32 ticker) external view returns (uint256) {
if (updatedAt[ticker] + 60 < block.timestamp) {
revert OracleDataRequired(oracle, abi.encode(ticker, "latest"), 0);
}
return price[ticker];
}
}
// Client side: prepend data until the simulation passes
async function prepare(tx) {
const calls = [tx];
for (;;) {
try { await simulate(calls); return calls; }
catch (e) {
const err = decodeOracleDataRequired(e); // parse the revert data
if (!err) throw e;
const signed = await fetchFromOracle(err.oracleContract, err.oracleQuery);
calls.unshift({ to: err.oracleContract, data: encodeFulfill(signed), value: err.feeRequired });
}
}
}
Things to know
- Status is Draft: interfaces may still change.
- The standard does not define how the data is verified. Safety rests entirely on the oracle contract's signature checks and staleness rules.
- Wallets that cannot decode multicalls may show users an opaque batch. The spec flags this as the main UX and security concern.
- Using a URI as the oracle id makes the pattern work with arbitrary HTTP endpoints, similar to ERC-3668.