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
  • Example Deployment
  • Github Repo
  • System Diagram
  • Methodology
  • Finding appropriate transactions
  • Components
  1. Examples

Autonomous Airdrop

Let users autonomously qualify themselves for airdrops based on contract-specified criteria.

PreviousQuickstartNextAxiomREPL Code

Last updated 1 year ago

Introduction

This Autonomous Airdrop example checks if a user has used Uniswap on Goerli (swapping a token for a token that is not ETH) on or after block 9000000, and if so, sends 100 UselessToken to the user. UselessToken is a test token and has no monetary value.

WARNING: This code is not audited and is only provided as an example.

Example Deployment

Github Repo

System Diagram

Methodology

For the airdrop parameters that we've specified, we'd like to figure out exactly how we can get this data from the blockchain. First, we'll dive a little deeper into how event logs work.

We're looking at one example transaction right now, but the guidelines we'll build will be universal for all transactions. In order to show that a user has performed a Swap on the UniswapUniversalRouter on or after block 9000000, we want to use the following four pieces of data:

  • The event schema for the event (see note below for details), which always lives on topic index 0 of the event, matches the Swap event above

  • The recipient field of the Swap event matches the user's address

  • The receipt's blockNumber is >= 9000000

  • The transaction's to field matches UniswapUniversalRouter's contract address

Swap(address,address,int256,int256,uint160,uint128,int24)

Finding appropriate transactions

Components

This example contains 3 parts: the AxiomREPL code, contracts, scripts, and webapp. AxiomREPL Code is the code that's written in using AxiomREPL to generate a ZK circuit in browser that can be used in your web app. Contracts contains all of the Solidity contract code to implement preprocessing the transaction data. Web App contains the code for a Next.js 13 (app router) web app.

When a Solidity contract emits an event, that event is saved in the transaction receipt's logs array. This array contains every event that was emitted during that transaction. Each log records up to 3 topics and some amount of data. topics are marked as indexed in the event and are easily searchable, whereas data is any field without indexed and is not as easily searchable. Here's an example Swap event at here that we're interested in for our airdrop parameters.

Note: you can use to validate that the Swap event schema 0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67 is indeed equal to the keccak256 hash (with 0x prepended) of the function signature:

We utilize to grab all transactions from the user that fit the criteria that it was sent from the user's address to the UniswapUniversalRouter's address. For each transaction, we get the receipt as well and then we parse through that data according to the 4 parameters outlined above to find an appropriate Event that matches.

this transaction
this online keccak256 tool
Alchemy's Transaction JSON-RPC
AxiomREPL Code
Contract
Web App
https://autonomous-airdrop-example.vercel.app/
https://github.com/axiom-crypto/autonomous-airdrop-example
Flow diagram for the full Autonomous Airdrop system
Swap event