๐ŸงนSpam NFT

Learn how to use Airstack to filter out spam NFTs and check whether an NFT is a spam or not.

Airstack provides easy-to-use NFT APIs for enriching Web3 applications with onchain and offchain NFT 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 NFT Balances Of User(s)

Fetching

First, you can fetch the NFT balances of user(s) and show each NFT 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

Show users' NFT balances and check if each NFT is a spam or not

Code

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

Formatting

Using the GraphQL response, you can filter out and aggregate the NFTs across Ethereum and Base by providing the response to the data input of the filterSpamNFTs function:

interface NFT {
  tokenAddress: string;
  tokenId: string;
  tokenType: string;
  token: {
    isSpam: boolean;
    name: string;
    symbol: string;
  };
}

interface NFTWithBlockchain extends NFT {
  blockchain: "ethereum" | "base";
}

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

const filterSpamNFTs = (
  data: TokenBalancesResponse
): NFTWithBlockchain[] | undefined => {
  try {
    const { Ethereum, Base } = data ?? {};
    const ethNfts =
      Ethereum?.TokenBalance?.map((nft: NFT) =>
        nft?.token?.isSpam
          ? null
          : {
              ...nft,
              blockchain: "ethereum",
            }
      ) ?? [];
    const baseNfts =
      Base?.TokenBalance?.map((nft: NFT) =>
        nft?.token?.isSpam
          ? null
          : {
              ...nft,
              blockchain: "base",
            }
      ) ?? [];
    return [...ethNfts, ...baseNfts]?.filter(Boolean) as NFTWithBlockchain[];
  } 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": "0x932261f9fc8da46c4a22e31b45c4de60623848bf",
    "tokenId": "144778",
    "tokenType": "ERC721",
    "token": { "isSpam": false, "name": "Zerion DNA 1.0", "symbol": "DNA" },
    "blockchain": "ethereum"
  },
  // Other Ethereum non-spam NFTs
  {
    "tokenAddress": "0x7f9f222d2c492bf3c876ecb03a148884b90020f8",
    "tokenId": "748",
    "tokenType": "ERC721",
    "token": {
      "isSpam": false,
      "name": "I Called Congress - FIT21",
      "symbol": "SWCFIT21"
    },
    "blockchain": "base"
  }
  // Other Base non-spam NFTs
]

Check If NFT Collection(s) Are Spam Or Not

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

Try Demo

Check if @BoredApeYachtClub, @Ethereum Name Service, and @Pudgy Penguins are spam NFTs or not

Code

query MyQuery {
  Tokens(
    input: {
      filter: {
        type: { _in: [ERC1155, ERC721] }
        address: {
          _in: [
            "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D"
            "0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85"
            "0xBd3531dA5CF5857e7CfAA92426877b022e612cf8"
          ]
        }
      }
      blockchain: ethereum
    }
  ) {
    Token {
      isSpam
      address
      name
      symbol
      type
    }
  }
}

Show All Non-Spam NFTs

You can use Airstack to fetch all existing non-spam NFTs across Ethereum, Base, and Zora:

Try Demo

Show all non-spam NFTs on Ethereum and Base

Code

query MyQuery {
  Ethereum: Tokens(
    input: {
      filter: { isSpam: { _eq: false }, type: { _in: [ERC1155, ERC721] } }
      blockchain: ethereum
    }
  ) {
    Token {
      isSpam
      address
      name
      symbol
      type
    }
    pageInfo {
      hasNextPage
      hasPrevPage
      nextCursor
      prevCursor
    }
  }
  Base: Tokens(
    input: {
      filter: { isSpam: { _eq: false }, type: { _in: [ERC1155, ERC721] } }
      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?