Reading Query Results
How to read query results from Axiom.
The areResponsesValid
view function in the AxiomV1Query
contract allows users to read block, account, and storage data from verified query results. This function has the following signature:
Using the Axiom SDK to read query results
The Axiom SDK provides an interface to help you read verified results from Axiom. To start reading query results, first use the getResponseTreeForKeccakQueryResponse
function to look up the a responseTree
for the query which contains information about the result. This will require looking up the query by the keccakQueryResponse
from the build
function in QueryBuilder
:
The responseTree
contains blockTree
, accountTree
, and storageTree
, which encapsulate all information about blocks, accounts, and storage, respectively. The next step is to use getHexRoot()
on each of the trees to generate keccakBlockResponse
, keccakAccountResponse
, and keccakStorageResponse
, which encode the verified query result on-chain:
Finally, format the block, account, and storage information you wish to verify by calling getValidationWitness
which will return a ValidationWitnessResponse
object with blockReponse
, accountResponse
, and storageResponse
fields. Depending on the type of data you are interested in querying (see table below), you can use the specific appropriate getValidationWitness function call.
block number
block hash
block number
address
nonce
balance
storage root
code hash
block number
address
slot number
slot value
In all cases, you will be passing in the data that you originally built the Query
with.
Block data
To get the ValidationWitness
for any of the data in the Block data column of the table above (block number or block hash), add the blockNumber for the QueryRow
that you added to the QueryBuilder
.
Account data
To get the ValidationWitness
for any of the data in the Account data column of the table above (block number, address, nonce, balance, storage root, or code hash), add the blockNumber and address for the QueryRow
that you added to the QueryBuilder
.
Storage data
To get the ValidationWitness
for any of the data in the Account data column of the table above (block number, address, slot number, slot value), add the blockNumber, address, and storage for the QueryRow
that you added to the QueryBuilder
.
Verifying the data on-chain
The ValidationWitnessResponse
contains a blockResponse
, an optional accountResponse
object, and an optional storageResponse
object. The type of data that you created the QueryRow
for is the same type that you will push to either the BlockResponse[]
, AccountResponse[]
, or StorageResponse[]
arrays that you will pass in to the areResponsesValid function.
You are now ready to verify this data against the on-chain result by calling the areResponsesValid
view function:
Information is available here on how to use the data in your own smart contract.
Advanced on-chain reads
For more advanced users, we offer access to the raw Merkle-ized query results via isKeccakResultValid
and isPoseidonResultValid
. These allow validation of Keccak and Poseidon encoded block, account, and storage data in the Axiom Query Format. The Poseidon format may be especially useful for ZK developers.
Last updated