Axiom V2 Docs Old
  • Introduction
    • What is Axiom?
    • Quickstart
  • Examples
    • Autonomous Airdrop
      • AxiomREPL Code
      • Contract
      • Web App
      • DataQuery-only Version
  • Developers
    • Axiom for Developers
    • Specifying a Query into Axiom
    • AxiomREPL
      • AxiomREPL Examples
    • Exporting a Client Side Prover
    • Handling Axiom Callbacks
    • Common Issues
      • Callback Debugging
  • SDK and REPL Reference
    • Axiom SDK Reference
      • QueryBuilderV2
      • Data Subqueries
        • Header Subquery
        • Account Subquery
        • Storage Subquery
        • Transaction Subquery
        • Receipt Subquery
        • Solidity Nested Mapping Subquery
    • AxiomREPL Reference
      • Circuit Types
      • Circuit Functions
      • Data Functions
      • Compute Functions
  • Protocol Design
    • Architecture Overview
    • Caching Block Hashes
    • Axiom Query Protocol
      • Axiom Query Format
    • ZK Circuits for Axiom Queries
    • Ethereum On-chain Data
    • Guardrails
  • Transparency and Security
    • KZG Trusted Setup
    • Contract Addresses
    • On-chain ZK Verifiers
    • Security
  • Zero Knowledge Proofs
    • Introduction to ZK
    • ZK Examples
    • Getting Started with halo2
    • halo2-repl
  • Additional Resources
    • Axiom V2 Explorer
    • Github
    • Website
    • Telegram
    • Discord
    • Axiom V1 Docs
Powered by GitBook
On this page
  • What are we building?
  • Setting up environment variables
  • Package installation
  • AxiomREPL
  • Code
  • Export
  • Sending a Query
  • Viewing the sent Query
  • Using the data in your contract
  • Deployment Addresses
  1. Introduction

Quickstart

Get started with Axiom V2 on Goerli Testnet

PreviousWhat is Axiom?NextAutonomous Airdrop

Last updated 1 year ago

What are we building?

In this Quickstart documentation, we'll be building an basic Next.js web app that implements an Axiom client-side prover to generate a ZK proof of a user's average account balance over the past

Start by cloning this Quickstart repository:

Setting up environment variables

You'll need a key from and a to place in your environmental variables. You can make a copy of and rename .env.local.example to .env.local:

.env.local
NEXT_PUBLIC_ALCHEMY_KEY=<alchemy key>
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=<walletconnect project ID>
NEXT_PUBLIC_MOCK=true

Package installation

Install required node.js packages with the following command:

Terminal
npm install

AxiomREPL

We'll first build a circuit in AxiomREPL. AxiomREPL allows developers to specify data fetching and computation for their specific use cases. This circuit will be exported as a client-side prover that will run in the user's browser, with the values in the inputs panel (bottom) that will be overridden by values provided by the Next.js web app. We've included this AxiomREPL link with the code:

Code

The same code in the above link is below:

AxiomREPL: Code
// Number of periods to run for; must be constant so circuit is deterministic
const periods = 10;

// Get the total account balance over the periods
let total = witness(0);
for (let i = 0; i < periods; i++) {
    const targetBlock = sub(endBlock, mul(constant(i), blockInterval));
    const bal = getAccount(targetBlock, user).balance().toCircuitValue();
    total = add(total, bal);
}

// Divide by number of periods to get the average account balance
const avgBalance = div(total, constant(periods));

// Add the average account balance to the callback
addToCallback(avgBalance);
AxiomREPL: Inputs
{
    "user": "0xf591C4c1e179A5E16407116882f7F8a524D51d14",
    "endBlock": 10000000,
    "blockInterval": 50000
}

Export

We want to export the TypeScript circuit.ts file, which we'll place into the cloned Quickstart repo:

Copy the exported circuit.ts file into the following directory inside the Quickstart, overriding the current file that's there:

src/components/axiom/worker/circuit.ts

Now, you have everything that you need to send a Query into the AxiomV2Query contract.

Sending a Query

In order to send a Query, you can start the Next.js dev server and go through a potential user flow:

  1. Run the development server

npm run dev

Generating client-side proofs is only supported in Google Chrome and Safari. Firefox is currently not supported.

  1. Connect your wallet

  2. Click the Build and Send Query button (query will require 0.0205 Goerli ETH)

Viewing the sent Query

The callback transaction contains an event that has the axiomResults data (the average balance of the account):

Using the data in your contract

The callback will output the results of the addToCallback calls (in the order that you called addToCallback) as an array of bytes32[] values.

Deployment Addresses

See Contract Addresses.

The development server will start at the default address of . which you can open in your web browser.

All Queries and their statuses are visible in (V2 Goerli w/ mock proofs).

See the section for more information.

https://github.com/axiom-crypto/axiom-quickstart
Alchemy
project ID from WalletConnect
https://repl.axiom.xyz?gist=a0ae0d93983ceb1f9c57e4bfe045bb13
http://localhost:3000
Axiom Explorer
Handling Axiom Callbacks
Export the TypeScript circuit from AxiomREPL
Callback axiomResults data is just directly emitted from the deployed ExampleClient contract
send from the Quickstart example
Example Query