🚩Third-party API

Using a third-party API to verify the users information.

In some verifications, we use api third-party api to verify the user's address. (Ex. Etherscan API, graph protocol API, Opensea.)

- Swap Count on Uniswap (Etherscan API)

We set up a simple verification system in the form of AWS CDK. If you are interested, please check it out.

- Uniswap V2 User Quest

In the case of Uniswap V2, we use graph protocol API and check whether user swap befero 1380481 or not.

import axios from "axios";
import { getProviderForNetwork } from "../../helpers/phiUtils";

/* -------------------------------- NETWORK -------------------------------- */
// number of the block you want to get timestamp of
const NETWORK = "homestead";
const blockNumber = 13804681;
/* ------------------------------------------------------------------------- */
type Swap = {
  id: number;
  timestamp: number;
  sender: string;
};

type APIResponse = {
  data: {
    swaps: Swap[];
  };
};
/* ------------------------------------------------------------------------- */
const endpoint = "https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2";
/* ------------------------------------------------------------------------- */
let provider: any;
// value is condition of count 
export async function verify(address: string, value: number): Promise<[boolean, number]> {
  if (!provider) {
    provider = await getProviderForNetwork(NETWORK);
  }
  const timestamp = (await provider.getBlock(blockNumber)).timestamp;

  const query = `
    query {
      swaps (
        where: {
          timestamp_lte: "${timestamp}", to: "${address}"
        }
      ) {
        id
        timestamp
        to
      }
    }
    `;
  const result = await axios.post<APIResponse>(endpoint, { query });
  const swapsLength = result.data.data.swaps.length;
 
 //if true, user get coupon
  if (swapsLength >= value) {
    return [true, swapsLength];
  } else {
    return [false, swapsLength];
  }
}

Snapshot Voting Quest

In the case of Snaphot, we use snapshot graph api and check count of votes.

const endpoint = "https://hub.snapshot.org/graphql";
const query = `
    query Votes {
      votes (
        first: ${value}
        skip: 0
        where: {
          voter: "${address}"
        }
      ) {
        id
        voter
      }
    }
    `;
const result = await retryableApiPost<APIResponse>(endpoint, { query });
  counter = result.data.votes.length;
  
// if true, user get coupon
  if (counter >= value) {
    return [true, counter];
  } else {
    return [false, counter];
  }

Last updated