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:
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:
{"data": {"Ethereum": {"TokenBalance": [ {"tokenAddress":"0x932261f9fc8da46c4a22e31b45c4de60623848bf","tokenId":"144778","tokenType":"ERC721","token": {"isSpam":false,// Not a spam NFT"name":"Zerion DNA 1.0","symbol":"DNA" } }, {"tokenAddress":"0x38f62679130121c85f28fb0c67dad560fab5688e","tokenId":"0","tokenType":"ERC1155","token": {"isSpam":true,// A spam NFT"name":"$3,000 OP Reward","symbol":"$,3000 OP Reward" } },// Other Ethereum NFTs ] },"Base": {"TokenBalance": [ {"tokenAddress":"0x7f9f222d2c492bf3c876ecb03a148884b90020f8","tokenId":"748","tokenType":"ERC721","token": {"isSpam":false,"name":"I Called Congress - FIT21","symbol":"SWCFIT21" } }, ],// Other Base NFTs } }}
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:
from typing import List, Dict, Any, Optionalimport tracebackdeffilter_spam_nfts(data: Optional[Dict[str, Any]]) -> List[Dict[str, Any]]:try: ethereum = data.get('Ethereum', {})if data else{} polygon = data.get('Polygon', {})if data else{} base = data.get('Base', {})if data else{} eth_nfts = [{**nft,'blockchain':'ethereum'}for nft in ethereum.get('TokenBalance', [])if nft andnot nft.get('token', {}).get('isSpam') ] polygon_nfts = [{**nft,'blockchain':'polygon'}for nft in polygon.get('TokenBalance', [])if nft andnot nft.get('token', {}).get('isSpam') ] base_nfts = [{**nft,'blockchain':'base'}for nft in base.get('TokenBalance', [])if nft andnot nft.get('token', {}).get('isSpam') ]return [nft for nft in eth_nfts + polygon_nfts + base_nfts if nft]exceptException: error = traceback.print_exc()raiseException(error)
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
Code
queryMyQuery { Tokens( input: {filter: {type: { _in: [ERC1155, ERC721] }address: {_in: ["0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D""0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85""0xBd3531dA5CF5857e7CfAA92426877b022e612cf8" ] } }blockchain: ethereum } ) { Token { isSpam address name symbol type } }}
{"data": {"Tokens": {"Token": [ {"isSpam":false,// not spam NFT"address":"0x57f1887a8bf19b14fc0df6fd9b2acc9af147ea85","name":"Ethereum Name Service","symbol":"ENS","type":"ERC721" }, {"isSpam":false,// not spam NFT"address":"0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d","name":"BoredApeYachtClub","symbol":"BAYC","type":"ERC721" }, {"isSpam":false,// not spam NFT"address":"0xbd3531da5cf5857e7cfaa92426877b022e612cf8","name":"PudgyPenguins","symbol":"PPG","type":"ERC721" } ] } }}
Show All Non-Spam NFTs
You can use Airstack to fetch all existing non-spam NFTs across Ethereum, Base, and Zora: