🔄Trending Swaps

Learn how to use Airstack to recommend trending ERC-20 tokens to swap for your users based on various conditions.

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

Trending Swaps are currently available for the Base and Ethereum blockchains.

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:

React

npm install @airstack/airstack-react

Node

npm install @airstack/node

Then, add the following snippets to your code:

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>;
  }
};

Other Programming Languages

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

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

NameValueDescription

blockchain

ethereum | base

Blockchain to fetch the trending swaps, either Ethereum or Base.

timeFrame

one_hour | two_hours | eight_hours | one_day | two_days | seven_days

Only fetch trending swaps within the chosen time frame, e.g. one_hour will fetch trending mints for the last 1 hour.

criteria

buy_transaction_count | sell_transaction_count | total_transaction_count | buy_volume | sell_volume | total_volume | unique_buy_wallets | unique_sell_wallets | total_unique_wallets

This will calculate and sort the tokens based on the chosen criteria: - buy_transaction_count: Calculate the number of buy transactions

- sell_transaction_count: Calculate the number of sell transactions

- total_transaction_count: Calculate the number of buy & sell transactions - buy_volume: Calculate the number of buying volumes.

- sell_volume: Calculate the number of selling volumes.

- total_volume: Calculate the number of buying & selling volumes. - unique_buy_wallets: Calculate the number of unique buyer wallets - unique_sell_wallets: Calculate the number of unique seller wallets - total_unique_wallets: Calculate the number of unique buyer & seller wallets

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

Try Demo

Show all trending swaps evaluated by the total buying and selling volume in the last 1 hour

Code

query TrendingSwaps(
  $blockchain: TrendingSwapsBlockchain!
  $criteria: TrendingSwapsCriteria!
  $timeFrame: TimeFrame!
) {
  TrendingSwaps(
    input: {
      timeFrame: $timeFrame
      criteria: $criteria
      blockchain: $blockchain
    }
  ) {
    TrendingSwap {
      address
      blockchain
      buyTransactionCount
      buyVolume
      sellTransactionCount
      sellVolume
      timeFrom
      timeTo
      totalTransactionCount
      totalUniqueWallets
      totalVolume
      uniqueBuyWallets
      uniqueSellWallets
      token {
        name
        symbol
      }
    }
  }
}

🎉 đŸĨŗ Congratulations you've just fetched all the trending tokens to swap and integrate it into your application!

Developer Support

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

More Resources

Last updated