Axiom V2 Docs
Search
K
Comment on page

Handling Axiom Callbacks

Using Axiom-verified results in your contract
Callbacks are triggered automatically once your query is fulfilled by Axiom. The ZK proof of your query's validity is verified via Axiom's on-chain verifier before the callback to your smart contract is called.

Specifying a Callback in the CLI

Specifying a Callback in the Client SDK

Receiving the Callback

In order to properly receive the Axiom V2 callback in your contract, you'll need to create a function that has the following argument format:
function axiomV2Callback(
uint64 sourceChainId,
address caller,
bytes32 querySchema,
uint256 queryId,
bytes32[] calldata axiomResults,
bytes calldata extraData
) external {
// validate msg.sender against the AxiomV2Query address
<...>
// validate the sourceChainId, caller, querySchema, and queryId
<...>
// perform your application logic
<...>
}
  • sourceChainId: The numerical ID of the chain that the query was generated from
  • caller: The original contract or EOA that sent the query to Axiom V2
  • querySchema: A unique hash identifier of the client circuit used to specify the query
  • queryId: A unique identifier for the submitted query, including user-specific information such as the caller and callback addresses
  • axiomResults: An array of the results in bytes32 format
    • Your results will be returned in the order and number of times in which you called addToCallback(value)
For examples of how to write your callback to integrate with Axiom, see Smart Contract Integration.

Parsing the Callback

When you receive the callback, you will want to validate that all of the fields (especially the sourceChainId and querySchema) match so that no one who maliciously submits a Query with invalid data is able to pass the validation.
Additionally, you will want to parse the axiomResults array to ensure that the data that is passed in matches all of the conditions that are required for the user. For example, if you require that a user submits a proof that their account balance is above 1 ETH at some historic block, you'll likely want to validate that the value of the index of the axiomResults array of the account balance is greater than 1 ETH.

Examples

Last modified 11d ago