Skip to content

Latest commit

 

History

History
247 lines (191 loc) · 6.33 KB

all-base-users.md

File metadata and controls

247 lines (191 loc) · 6.33 KB
description layout
Learn how to recommend ERC-20 tokens that are trending amongst all Base users.
title description tableOfContents outline pagination
visible
true
visible
true
visible
true
visible
visible
true

🔵 All Base Users

In this guide, you will learn how to use Airstack to recommend all trending tokens among all Base users within a given time frame. This API makes use of Airstack Abstractions to calculate the results in milliseconds; no compute or backend database required on your end.

Pre-requisites

  • An Airstack account
  • Basic knowledge of GraphQL

Get Started

JavaScript/TypeScript/Python

If you are using JavaScript/TypeScript or Python, Install the Airstack SDK:

{% tabs %} {% tab title="npm" %} React

npm install @airstack/airstack-react

Node

npm install @airstack/node

{% endtab %}

{% tab title="yarn" %} React

yarn add @airstack/airstack-react

Node

yarn add @airstack/node

{% endtab %}

{% tab title="pnpm" %} React

pnpm install @airstack/airstack-react

Node

pnpm install @airstack/node

{% endtab %}

{% tab title="pip" %}

pip install airstack

{% endtab %} {% endtabs %}

Then, add the following snippets to your code:

{% tabs %} {% tab title="React" %}

import { init, useQuery } from "@airstack/airstack-react";

init("YOUR_AIRSTACK_API_KEY");

const query = `YOUR_QUERY`; // Replace with GraphQL Query

const Component = () => {
  const { data, loading, error } = useQuery(query);

  if (data) {
    return <p>Data: {JSON.stringify(data)}</p>;
  }

  if (loading) {
    return <p>Loading...</p>;
  }

  if (error) {
    return <p>Error: {error.message}</p>;
  }
};

{% endtab %}

{% tab title="Node" %}

import { init, fetchQuery } from "@airstack/node";

init("YOUR_AIRSTACK_API_KEY");

const query = `YOUR_QUERY`; // Replace with GraphQL Query

const { data, error } = await fetchQuery(query);

console.log("data:", data);
console.log("error:", error);

{% endtab %}

{% tab title="Python" %}

import asyncio
from airstack.execute_query import AirstackClient

api_client = AirstackClient(api_key="YOUR_AIRSTACK_API_KEY")

query = """YOUR_QUERY""" # Replace with GraphQL Query

async def main():
    execute_query_client = api_client.create_execute_query_object(
        query=query)

    query_response = await execute_query_client.execute_query()
    print(query_response.data)

asyncio.run(main())

{% endtab %} {% endtabs %}

Other Programming Languages

To access the Airstack APIs in other languages, you can use https://api.airstack.xyz/gql as your GraphQL endpoint.

Fetch Trending Tokens Globally

First, define the following parameters to fetch the trending tokens data:

NameValueDescription
transferTypeall | self_initiatedThis will either include all types of transactions (including airdrops & self-transfers) or only self-initiated transactions.
timeFrameone_hour | two_hours | eight_hours | one_day | two_days | seven_daysOnly fetch trending tokens within the chosen time frame, e.g. one_hour will fetch trending mints for the last 1 hour.
criteriaunique_wallets | total_transfers | unique_holdersThis will calculate and sort the tokens based on the chosen criteria:
- unique_wallets: Calculate the number of unique wallets transfer the trending tokens
- total_transfers: Calculate the number of times transfers occurred on the trending token
- unique_holders: Calculate the number of unique wallets that hold the trending tokens
swappablebooleanThis will only return tokens that are swappable if set to true. Otherwise, include all tokens whether swappable or not in DEX.

Once you have the parameters prepared, simply use the query below and add the parameters as variables:

Try Demo

{% embed url="https://app.airstack.xyz/query/hYewVUxEXR" %} Show all trending tokens among all Base users by the number of unique wallets in the last 1 hour {% endembed %}

Code

{% tabs %} {% tab title="Query" %}

query MyQuery(
  $transferType: TrendingTokensTransferType!,
  $timeFrame: TimeFrame!,
  $criteria: TrendingTokensCriteria!,
  swappable: { _eq: $swappable }
) {
  TrendingTokens(
    input: {
      transferType: $transferType,
      timeFrame: $timeFrame,
      audience: all,
      blockchain: base,
      criteria: $criteria,
      swappable: { _eq: $swappable }
    }
  ) {
    TrendingToken {
      address
      criteriaCount
      timeFrom
      timeTo
      token {
        name
        symbol
        type
      }
    }
  }
}

{% endtab %}

{% tab title="Variables" %}

{
  "transferType": "self_initiated",
  "timeFrame": "one_hour",
  "criteria": "unique_wallets",
  "swappable": true,
}

{% endtab %}

{% tab title="Response" %}

{
  "data": {
    "TrendingTokens": {
      "TrendingToken": [
        {
          "address": "0x940181a94a35a4569e4529a3cdfb74e38fd98631",
          "criteriaCount": 90,
          "timeFrom": "2024-03-15T09:40:00Z",
          "timeTo": "2024-03-15T10:40:00Z",
          "token": {
            "name": "Aerodrome",
            "symbol": "AERO",
            "type": "ERC20"
          }
        },
        // Other trending tokens
      ]
    }
  }
}

{% endtab %} {% endtabs %}

🎉 🥳 Congratulations you've just fetched all the trending tokens among all Base users and integrate it into your application!

Developer Support

If you have any questions or need help regarding integrating or building trending tokens into your application, please join our Airstack's Telegram group.

More Resources