Comment on page
Get started with Axiom V2 on Goerli Testnet
The absolute fastest way to get started is to clone the Axiom Quickstart repository and run the examples there. We will walk through how to do that in this guide.
git clone --recurse-submodules --shallow-submodules -j8 https://github.com/axiom-crypto/axiom-quickstart.git
# install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
# Install latest LTS node
nvm install --lts
# install Foundry using Foundryup
curl -L https://foundry.paradigm.xyz | bash
You will also need to export a JSON-RPC provider URL as an environmental variable:
export PROVIDER_URI_GOERLI=<your provider url>
For the quickstart to work, your JSON-RPC provider will need to have access to an archive node.
Lastly we install the packages in the quickstart repo itself:
An Axiom Query is specified by writing a special Axiom client circuit that uses historical Ethereum data and performs compute on that data. This can be done in Typescript using the
For this quickstart we'll just use an example circuit in
axiom/circuit.ts. The circuit code is defined in a function called
nonceIncrementor. This circuit takes in a variable
addressas input, makes a request to Axiom to verify the nonce of the
addressat the given
blockNumber, and increments the nonce by
1inside the circuit. The circuit outputs, which are forwarded to your callback contract, are
[blockNumber, address, nonce + 1]as a
We need to provide a smart contract that the
AxiomV2Querycontract will call after Axiom has fulfilled the query specified above. This contract is what receives the outputs of the circuit we wrote above.
We have an example smart contract
src/AxiomNonceIncrementor.sol. This contract inherits the abstract contract
AxiomV2Clientwhich implements some generic scaffolding to set up a contract to receive Axiom callbacks. The functions to override are
In our example, in
[blockNumber, address, nonceInc]from the callback and simply store
nonceIncin a mapping
blockToAddrToNonceInc[blockNumber][address] = nonceIncand emit an event.
We have provided a Foundry test in
test/AxiomNonceIncrementor.t.solof deploying the example contract, sending a query, pranking Axiom fulfillment, and executing the callback. You can run it with
forge test --mt testAxiomFulfillQuery -vvvv
The verbose output of the test will show the details of the callback and the event our
AxiomNonceIncrementorcontract emits at the end of the callback function.
In our Foundry test, we pranked the
AxiomV2Queryfulfillment for developer convenience. This means that the historical data of the account
noncewas unverified. To fully test the Axiom integration, you will need to send your query on-chain for Axiom to fulfill. To learn how to do that, go to Sending Queries On-Chain.
Last modified 4d ago