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
  • Introduction
  • Inputs
  • Code
  1. Examples
  2. Autonomous Airdrop

AxiomREPL Code

The code for AxiomREPL

PreviousAutonomous AirdropNextContract

Last updated 1 year ago

Introduction

allows users to write custom ZK circuits in Javascript. We use it here to generate a circuit that proves our request for the parameters from the Swap event and the same transaction's to field.

The goal of writing the AxiomREPL code in this section is to export it for use in our Web App that we'll build after this.

AxiomREPL is located at

Inputs

We have the following inputs to our AxiomREPL code. These inputs are variables that can later be changed (outside of AxiomREPL) in your app. Once the circuit has been exported outside of AxiomREPL into your web app, a different blockNumber, txIdx, and logIdx for a different user's Swap transaction can be inserted by your web app and used in the circuit.

Inputs
{
    "blockNumber": 9610835,
    "txIdx": 6,
    "logIdx": 3
}

Note: every transaction hash maps to a unique blockNumber and txIdx combination.

Code

The following code implements logic for getting blockchain data and running compute over that data. The inputs from the input box are used here, but this code cannot be changed once it is exported into your web app. Only the variables in the input field above may be changed by your web app.

If you do need to change your code, it must be done in AxiomREPL and then re-exported (because the verifying key will be different).

AxiomREPL code
// `Swap(address,address,int256,int256,uint160,uint128,int24)` event schema
const eventSchema =
  "0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67";

// specify and fetch the data you want Axiom to verify
let receipt = getReceipt(blockNumber, txIdx);
let receiptLog = receipt.log(logIdx); //get the log at index 3

// get the topic at index 0 (event schema)
let swapSchema = receiptLog.topic(0, eventSchema);

// get the topic at index 2
let swapTo = receiptLog.topic(2, eventSchema).toCircuitValue();

// get the block number for receipt
let blockNum = receipt.blockNumber().toCircuitValue();

// get the `to` field of the transaction
let tx = getTx(blockNumber, txIdx);
let txTo = tx.to().toCircuitValue();

// adds each of our desired variables to the callback. The callback returns the 
// values as an array in the order that `addToCallback` was called. 
addToCallback(swapSchema);
addToCallback(swapTo);
addToCallback(blockNum);
addToCallback(txTo);

// logs all of the variables to the right side output panel for sanity check
log(swapSchema);
log(swapTo);
log(blockNum);
log(txTo);

AxiomREPL
https://repl.axiom.xyz/