Reading Historic Block Data

Access historic block hashes from Axiom.

AxiomV1 caches historic block hashes back to genesis in a format explained here. Smart contracts can access any historic block header data in a trustless way by providing Merkle proofs into this cache.

To access this cache with the Axiom SDK, first fetch the BlockHashWitness:

import { Axiom, AxiomConfig } from "@axiom-crypto/core";

const config: AxiomConfig = {
    providerUri: <your provider uri (such as from Alchemy, Infura, etc)>,
    version: "v1",
}
const ax = new Axiom(config);

const blockHashWitness = ax.block.getBlockHashWitness(<blockNumber>);

Then verify on-chain using this BlockHashWitness:

import { ethers } from "ethers";

const providerUri = <your provider uri (such as from Alchemy, Infura, etc)>;
const provider = new ethers.JsonRpcProvider(providerUri);
const wallet = new ethers.Wallet(<private key>, provider);
const axiom = new ethers.Contract(
  ax.getAxiomAddress() as string,
  ax.getAxiomAbi(),
  wallet
);

const tx = await axiom.isBlockHashValid(
  blockHashWitness,
  {
    gasPrice: ethers.parseUnits("100", "gwei"),
  }
);

Last updated