🧹Spam ERC20

Learn how to use Airstack to filter out spam ERC20s and check whether an ERC20 token is a spam or not.

Airstack provides easy-to-use ERC20 token APIs for enriching Web3 applications with onchain and offchain ERC20 token data from Ethereum, Base, Degen Chain, and other Airstack-supported chains.

When indexing any new token, Airstack takes into consideration contract deployer address history, and other factors to determine if the token might be spam.

Those contracts are the marked spam and can be filtered out. If you think that a given contract was incorrectly labeled as spam, please reach out to us support@airstack.xyz.

Table Of Contents

In this guide you will learn how to use Airstack to:

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.

🤖 AI Natural Language​

Airstack provides an AI solution for you to build GraphQL queries to fulfill your use case easily. You can find the AI prompt of each query in the demo's caption or title for yourself to try.

Get Non-Spam ERC20 Token Balances Of User(s)

Fetching

First, you can fetch the ERC20 token balances of user(s) and show each ERC20 token whether they are a spam or not using the token.isSpam field from the TokenBalances API.

With the query below, provide an array of users' 0x addresses, ENS domains, cb.ids, Lens profiles, Farcaster fnames/fids to owner input:

Try Demo

Code

query MyQuery {
  Ethereum: TokenBalances(
    input: {
      filter: {
        owner: {
          _in: [
            "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
            "vitalik.eth"
            "lens/@vitalik"
            "fc_fname:vitalik.eth"
          ]
        }
        tokenType: { _eq: ERC20 }
      }
      blockchain: ethereum
    }
  ) {
    TokenBalance {
      tokenAddress
      token {
        isSpam
        name
        symbol
      }
    }
  }
  Polygon: TokenBalances(
    input: {
      filter: {
        owner: {
          _in: [
            "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
            "vitalik.eth"
            "lens/@vitalik"
            "fc_fname:vitalik.eth"
          ]
        }
        tokenType: { _eq: ERC20 }
      }
      blockchain: polygon
    }
  ) {
    TokenBalance {
      tokenAddress
      token {
        isSpam
        name
        symbol
      }
    }
  }
  Base: TokenBalances(
    input: {
      filter: {
        owner: {
          _in: [
            "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
            "vitalik.eth"
            "lens/@vitalik"
            "fc_fname:vitalik.eth"
          ]
        }
        tokenType: { _eq: ERC20 }
      }
      blockchain: base
    }
  ) {
    TokenBalance {
      tokenAddress
      token {
        isSpam
        name
        symbol
      }
    }
  }
}

Formatting

Using the GraphQL response, you can filter out and aggregate the ERC20 tokens across Ethereum, Base, Degen Chain, and other Airstack-supported chains by providing the response as to the data input of the filterSpamERC20Tokens function:

interface ERC20 {
  tokenAddress: string;
  token: {
    isSpam: boolean;
    name: string;
    symbol: string;
  };
}

interface ERC20WithBlockchain extends ERC20 {
  blockchain: "ethereum" | "polygon" | "base";
}

interface TokenBalancesResponse {
  Ethereum: {
    TokenBalance?: ERC20[];
  };
  Polygon: {
    TokenBalance?: ERC20[];
  };
  Base: {
    TokenBalance?: ERC20[];
  };
}

const filterSpamERC20Tokens = (
  data: TokenBalancesResponse
): ERC20WithBlockchain[] | undefined => {
  try {
    const { Ethereum, Polygon, Base } = data ?? {};
    const ethErc20Tokens =
      Ethereum?.TokenBalance?.map((erc20Token: ERC20) =>
        erc20Token?.token?.isSpam
          ? null
          : {
              ...erc20Token,
              blockchain: "ethereum",
            }
      ) ?? [];
    const polygonErc20Tokens =
      Polygon?.TokenBalance?.map((erc20Token: ERC20) =>
        erc20Token?.token?.isSpam
          ? null
          : {
              ...erc20Token,
              blockchain: "polygon",
            }
      ) ?? [];
    const baseErc20Tokens =
      Base?.TokenBalance?.map((erc20Token: ERC20) =>
        erc20Token?.token?.isSpam
          ? null
          : {
              ...erc20Token,
              blockchain: "base",
            }
      ) ?? [];
    return [
      ...ethErc20Tokens,
      ...polygonErc20Tokens,
      ...baseErc20Tokens,
    ]?.filter(Boolean) as ERC20WithBlockchain[];
  } catch (e) {
    console.error(e);
  }
};

The formatted data will combine Ethereum, Base, Degen Chain, and other Airstack-supported chains NFTs hold by the user and filtered out all spam NFTs:

[
  {
    "tokenAddress": "0xbaaa3b3b00def381c0794d0253a4a1ef3b2a9fbc",
    "token": {
      "isSpam": false,
      "name": "Monkeys George",
      "symbol": "Monkeys George"
    },
    "blockchain": "ethereum"
  },
  // Other Ethereum non-spam ERC20 tokens
  {
    "tokenAddress": "0xc2132d05d31c914a87c6611c10748aeb04b58e8f",
    "token": { "isSpam": false, "name": "(PoS) Tether USD", "symbol": "USDT" },
    "blockchain": "polygon"
  },
  // Other Polygon non-spam ERC20 tokens
  {
    "tokenAddress": "0xac1bd2486aaf3b5c0fc3fd868558b082a531b2b4",
    "token": { "isSpam": false, "name": "Toshi", "symbol": "TOSHI" },
    "blockchain": "base"
  }
  // Other Base non-spam ERC20 tokens
]

Check If ERC20 Token(s) Are Spam Or Not

You can use Airstack to check if ERC20 token(s) are spam or not by using Tokens API and providing the ERC20 token address(es) to address input:

Try Demo

Code

query MyQuery {
  Tokens(
    input: {
      filter: {
        type: { _eq: ERC20 }
        address: {
          _in: [
            "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
            "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"
            "0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0"
          ]
        }
      }
      blockchain: ethereum
    }
  ) {
    Token {
      isSpam
      address
      name
      symbol
      type
    }
  }
}

Show All Non-Spam ERC20 Tokens

You can use Airstack to fetch all existing non-spam ERC20 tokens across Ethereum, Base, Degen Chain, and other Airstack-supported chains:

Try Demo

Code

query MyQuery {
  Ethereum: Tokens(
    input: {
      filter: { isSpam: { _eq: false }, type: { _eq: ERC20 } }
      blockchain: ethereum
    }
  ) {
    Token {
      isSpam
      address
      name
      symbol
      type
    }
    pageInfo {
      hasNextPage
      hasPrevPage
      nextCursor
      prevCursor
    }
  }
  Polygon: Tokens(
    input: {
      filter: { isSpam: { _eq: false }, type: { _eq: ERC20 } }
      blockchain: polygon
    }
  ) {
    Token {
      isSpam
      address
      name
      symbol
      type
    }
    pageInfo {
      hasNextPage
      hasPrevPage
      nextCursor
      prevCursor
    }
  }
  Base: Tokens(
    input: {
      filter: { isSpam: { _eq: false }, type: { _eq: ERC20 } }
      blockchain: base
    }
  ) {
    Token {
      isSpam
      address
      name
      symbol
      type
    }
    pageInfo {
      hasNextPage
      hasPrevPage
      nextCursor
      prevCursor
    }
  }
}

Developer Support

If you have any questions or need help regarding fetching NFT details data, please join our Airstack's Telegram group.

More Resources

Last updated

Was this helpful?