ERC-7412

Use oracle data onchain

ERC-7412 is a standard that enables smart contracts on Ethereum to use cryptographically-signed price data, cross-chain data, and more.

When a function requires offchain data, it throws an OracleDataRequired error during simulation. The client library then fetches and prepends the required data to the transaction automatically.

Build with real-world data

Write smart contracts that call oracle contracts. Use your protocol with any app that has the client library installed.

Examples

Call view functions across chains

Verify .eth address ownership on an L2 via Wormhole Queries.

function verifyENSOwnership(address user, bytes ensNameNode) internal { // Query ENS ownership data on mainnet, 1 minute staleness tolerance QueryData memory queryData = QueryData({ chainId: 1, target: "0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e", data: abi.encodeWithSelector( IENSRegistry.owner.selector, ensNameNode ), asOfTimestamp: 0 // Get latest data }); bytes memory ownerData = wormholeOracleContract.getCrossChainData(queryData, 60); address ensOwner = abi.decode(ownerData, (address)); require(ensOwner == user, "User does not own this ENS name"); }

Integrate with price feeds

Fetch ETH prices from Pyth, Chainlink, and RedStone when issuing decentralized stablecoins.

function mintStablecoin(uint256 ethAmount) external { // Require ETH collateral require(msg.value == ethAmount, "Must send exact ETH amount"); // Get ETH price from Chainlink, 1 minute staleness tolerance bytes memory chainlinkData = chainlinkOracleContract.getLatestPrice( CHAINLINK_ETH_FEED, 60 ); uint256 chainlinkPrice = abi.decode(chainlinkData, (uint256)); // Get ETH price from Pyth, 1 minute staleness tolerance bytes memory pythData = pythOracleContract.getLatestPrice( PYTH_ETH_FEED, 60 ); uint256 pythPrice = abi.decode(pythData, (uint256)); // Get ETH price from Redstone, 1 minute staleness tolerance bytes memory redstoneData = redstoneOracleContract.getLatestValue( REDSTONE_ETH_FEED, 60 ); uint256 redstonePrice = abi.decode(redstoneData, (uint256)); // Average the prices uint256 avgPrice = (chainlinkPrice + pythPrice + redstonePrice) / 3; // Calculate stablecoins to mint with 200% collateralization ratio uint256 stableAmount = (ethAmount * avgPrice) / (2 * 1e18); // Issue stablecoins to the user _mint(msg.sender, stableAmount); }
built with heart by dbeal-eth + noahlitvin