Accessing Block and Query Information

Access block and query information from the Axiom SDK

We provide information about Ethereum blocks and Axiom queries via the Block and Query classes wrapped by the Axiom class.

Block Information

Block information to use in reading from AxiomV1 is available from the Block object ax.block. The available API calls are as follows.

getBlockHashWitness

async getBlockHashWitness(blockNumber: number): Promise<BlockHashWitness | null> 

Returns a BlockHashWitness to verify a single block hash against the cache in AxiomV1 in the isBlockHashValid contract call.

getBlockRlpHeader

async getBlockRlpHeader(blockNumber: number): Promise<string | null>

Returns the RLP-encoded block header of block blockNumber.

getBlockMmrProof

async getBlockMmrProof(blockNumber: number): Promise<any | null> 

Returns mmr, claimedBlockHash, and merkleProof of the block hash of block blockNumber to verify a single block hash against the cache in AxiomV1 using the mmrVerifyBlockHash contract call.

Query Information

Information about queries into Axiom is available from the Query object ax.query. The available API calls are as follows.

getResponseTreeForQueryHash

async getResponseTreeForQueryHash(queryHash: string): Promise<ResponseTree>

Returns a ResponseTree object containing the data associated with a queryHash indexed by keccakQueryResponse. This object is defined by:

interface ResponseTree {
  blockTree: MerkleTree;
  accountTree: MerkleTree;
  storageTree: MerkleTree;
  rowHashMap: Map<string, number>;
  data: QueryData[];
}

and we can extract summary query responses from it by:

let responseTree = ax.query.getResponseTreeForQueryHash(queryHash);

const keccakBlockResponse = responseTree.blockTree.getHexRoot();
const keccakAccountResponse = responseTree.accountTree.getHexRoot();
const keccakStorageResponse = responseTree.storageTree.getHexRoot();

getResponseTreeForKeccakQueryResponse

async getResponseTreeForKeccakQueryResponse(keccakQueryResponse: string): Promise<ResponseTree>

Returns a ResponseTree object in the same manner and interface as above.

Query response components can be obtained by:

let responseTree = ax.query.getResponseTreeForKeccakQueryResponse(keccakQueryResponse);

const keccakBlockResponse = responseTree.blockTree.getHexRoot();
const keccakAccountResponse = responseTree.accountTree.getHexRoot();
const keccakStorageResponse = responseTree.storageTree.getHexRoot();

getResponseTreeFromTxHash

async getResponseTreeFromTxHash(txHash: string): Promise<ResponseTree>

Another way to get the ResponseTree from is by passing in a transaction hash. The transaction hash must be the one from a successful sendQuery call to AxiomV1Query.

getValidationWitness

getValidationWitness(
  responseTree: ResponseTree,
  blockNumber: number,
  address?: string,
  slot?: BigNumberish
): ValidationWitnessResponse | undefined 

Fetches a Merkle proof and some other data that allows a user to prove that their claimed data is actually committed to in keccakQueryResponse. This prepares the arguments for areResponsesValid which checks the witness data against the keccakQueryResponse which is already verified.

You can think of getValidationWitness as the second step in a 3-step process of receiving and verifying a proof:

  1. Receive a response from Axiom

  2. Prove that the response you got from Axiom is actually what is in keccackQueryResponse

  3. Check that the data that gets passed into your smart contract is the same data as in step 2 with areResponsesValid.

Returns SolidityBlockResponse, SolidityAccountResponse, and SolidityStorageResponse objects which can be used to read query results from areResponsesValid in AxiomV1Query. The interface of the return object is as follows:

interface ValidationWitnessResponse {
  blockResponse: SolidityBlockResponse;
  accountResponse?: SolidityAccountResponse;
  storageResponse?: SolidityStorageResponse;
}

The result is:

  • SolidityBlockResponse if neither address or slot is provided

  • SolidityAccountResponse if address is provided, but slot is not

  • SolidityStorageResponse if both address and slot are provided.

To see an example of how getValidationResponse is used, check out this example.

getQueryHashFromTxHash

async getQueryHashFromTxHash(txHash: string): Promise<string | undefined>

Gets the queryHash value from the transaction hash where the sendQuery function in the AxiomV1Query contract was called. Ensure that you are passing in the transaction hash from the sendQuery function call.

getKeccakQueryResponseFromTxHash

async getKeccakQueryResponseFromTxHash(txHash: string): Promise<string | undefined>

Gets the keccakQueryResponse from the transaction where the sendQuery function in the AxiomV1Query contract was called. Ensure that you are passing in the transaction hash from the sendQuery function call.

Last updated