---
eip: 7412
label: ERC-7412
title: On-Demand Off-Chain Data Retrieval
status: Draft
type: Standards Track
category: ERC
created: 2023-07-26
official: https://eips.ethereum.org/EIPS/eip-7412
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-7412.md
canonical: https://eips.huatuo.xyz/eip-7412/
lang: en
tldr: 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.
tags: [oracle, offchain, cross-chain, multicall, data]
---

# ERC-7412: On-Demand Off-Chain Data Retrieval

> A method to construct multicalls with prepended verifiable off-chain data

**TL;DR:** 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](/eip-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

1. 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 of `oracleQuery` is defined by the oracle, e.g. chain id + contract + calldata, or a ticker + timestamp.
2. The client (wallet or app SDK) sees this error while **simulating** the transaction. It looks up the `oracleId()` of `oracleContract`, finds a gateway for that oracle network (like resolving an RPC from a chain id), and fetches signed data.
3. The client builds a multicall: `fulfillOracleQuery(signedData)` first, then the original call. It simulates again and repeats until no more errors appear.
4. On-chain, `fulfillOracleQuery` verifies the signatures and stores the result, so the original call can now read it.

The oracle contract implements:

- `oracleId()`: a `bytes32` identifying the oracle network.
- `fulfillOracleQuery(bytes signedOffchainData)` (payable). If it charges a fee, it reverts with `FeeRequired(uint amount)` until enough `msg.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](/eip-4337/) smart accounts can do it natively, and EOAs can use [ERC-2771](/eip-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):

```solidity
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];
    }
}
```

```ts
// 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.


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-7412
