👛Token Mints

Learn how to use Airstack to fetch all ERC20/721/1155 token mints data, from or to user(s), across Ethereum, Base, Degen Chain, and other Airstack supported chains.

All tokens minted are essentially token transfers from a null address (0x00...00) to a user address that are executed by the receiving user itself. Thus, with Airstack, you can use the TokenTransfers API to fetch all user's token mints by specifying the input as follows:

Input FilterValueDescription

operator

user's 0x address, ENS, cb.id, Lens, or Farcaster

Executor of the transaction.

from

0x0000000000000000000000000000000000000000

Sender in the ERC20/721/1155 token transfers.

to

user's 0x address, ENS, cb.id, Lens, or Farcaster

Receiver in the ERC20/721/1155 token transfers.

You also have the option to add blockTimestamp filter to your query to fetch all tokens that are minted during a specified period of time:

Input FilterValueDescription

blockTimestamp

Specific time period to fetch token mints, use _gt or _gte and _lt or _lte filters to specify the timestamp period. Look at example below for NFT and ERC20 mints.

Allows entering blockTimestamp to filter transactions which happened in specific periods. Time format should be following the unix timstamp format, e.g. 2023-01-01T00:00:00Z

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 NFT Mints By A User

You can fetch all NFTs minted by a user, e.g. betashop.eth, across multiple chains, such as Ethereum, Base, Degen Chain, and other Airstack-supported chains, by using the TokenTransfers API:

Try Demo

Code

query MyQuery {
  Ethereum: TokenTransfers(
    input: {
      filter: {
        # Only get mints that are executed by the same user
        operator: {_eq: "betashop.eth"},
        # Mints are token transfers that has null address as `from`
        from: {_eq: "0x0000000000000000000000000000000000000000"},
        # Set this to the user that receive the token mints
        to: {_eq: "betashop.eth"},
        # Get only NFTs (ERC721/1155)
        tokenType: {_in: [ERC721, ERC1155]},
      },
      blockchain: ethereum,
      order: {blockTimestamp: DESC}
    }
  ) {
    TokenTransfer {
      blockchain
      formattedAmount
      tokenAddress
      tokenId
      tokenNft {
        metaData {
          name
        }
        contentValue {
          image {
            medium
          }
        }
      }
      tokenType
    }
  }
  Base: TokenTransfers(
    input: {
      filter: {
        # Only get mints that are executed by the same user
        operator: {_eq: "betashop.eth"},
        # Mints are token transfers that has null address as `from`
        from: {_eq: "0x0000000000000000000000000000000000000000"},
        # Set this to the user that receive the token mints
        to: {_eq: "betashop.eth"},
        # Get only NFTs (ERC721/1155)
        tokenType: {_in: [ERC721, ERC1155]},
      },
      blockchain: base,
      order: {blockTimestamp: DESC}
    }
  ) {
    TokenTransfer {
      blockchain
      formattedAmount
      tokenAddress
      tokenId
      tokenNft {
        metaData {
          name
        }
        contentValue {
          image {
            medium
          }
        }
      }
      tokenType
    }
  }
  Zora: TokenTransfers(
    input: {
      filter: {
        # Only get mints that are executed by the same user
        operator: {_eq: "betashop.eth"},
        # Mints are token transfers that has null address as `from`
        from: {_eq: "0x0000000000000000000000000000000000000000"},
        # Set this to the user that receive the token mints
        to: {_eq: "betashop.eth"},
        # Get only NFTs (ERC721/1155)
        tokenType: {_in: [ERC721, ERC1155]},
      },
      blockchain: zora,
      order: {blockTimestamp: DESC}
    }
  ) {
    TokenTransfer {
      blockchain
      formattedAmount
      tokenAddress
      tokenId
      tokenNft {
        metaData {
          name
        }
        contentValue {
          image {
            medium
          }
        }
      }
      tokenType
    }
  }
}

Get ERC20 Token Mints By A User

You can fetch all ERC20 tokens minted by a user, e.g. ipeciura.eth, across multiple chains, such as Ethereum, Base, Degen Chain, and other Airstack-supported chains, by using the TokenTransfers API:

Try Demo

Show me all ERC20 tokens minted by ipeciura.eth

Code

query MyQuery {
  Ethereum: TokenTransfers(
    input: {
      filter: {
        # Only get mints that are executed by the same user
        operator: {_eq: "ipeciura.eth"},
        # Mints are token transfers that has null address as `from`
        from: {_eq: "0x0000000000000000000000000000000000000000"},
        # Set this to the user that receive the token mints
        to: {_eq: "ipeciura.eth"},
        # Get only ERC20 tokens
        tokenType: {_eq: ERC20},
      },
      blockchain: ethereum,
      order: {blockTimestamp: DESC}
    }
  ) {
    TokenTransfer {
      blockchain
      formattedAmount
      tokenAddress
      token {
        name
      }
    }
  }
  Base: TokenTransfers(
    input: {
      filter: {
        # Only get mints that are executed by the same user
        operator: {_eq: "ipeciura.eth"},
        # Mints are token transfers that has null address as `from`
        from: {_eq: "0x0000000000000000000000000000000000000000"},
        # Set this to the user that receive the token mints
        to: {_eq: "ipeciura.eth"},
        # Get only ERC20 tokens
        tokenType: {_eq: ERC20},
      },
      blockchain: base,
      order: {blockTimestamp: DESC}
    }
  ) {
    TokenTransfer {
      blockchain
      formattedAmount
      tokenAddress
      token {
        name
      }
    }
  }
  Zora: TokenTransfers(
    input: {
      filter: {
        # Only get mints that are executed by the same user
        operator: {_eq: "ipeciura.eth"},
        # Mints are token transfers that has null address as `from`
        from: {_eq: "0x0000000000000000000000000000000000000000"},
        # Set this to the user that receive the token mints
        to: {_eq: "ipeciura.eth"},
        # Get only ERC20 tokens
        tokenType: {_eq: ERC20},
      },
      blockchain: zora,
      order: {blockTimestamp: DESC}
    }
  ) {
    TokenTransfer {
      blockchain
      formattedAmount
      tokenAddress
      token {
        name
      }
    }
  }
}

Get NFT Mints By A User in a Specified Period

You can fetch all NFTs minted during a specified period of time by a user, e.g. ipeciura.eth, across different chains, e.g. Ethereum, Base, Degen Chain, and other Airstack-supported chains, by using the TokenTransfers API:

Try Demo

Code

query MyQuery {
  TokenTransfers(
    input: {
      filter: {
        # Only get mints that are executed by the same user
        operator: {_eq: "ipeciura.eth"},
        # Mints are token transfers that has null address as `from`
        from: {_eq: "0x0000000000000000000000000000000000000000"},
        # Set this to the user that receive the token mints
        to: {_eq: "ipeciura.eth"},
        # Get only ERC721/1155 NFTs
        tokenType: {_in: [ERC721, ERC1155]},
        # Specify time stamp (in 2023)
        blockTimestamp: {
          _gt: "2023-01-01T00:00:00Z", # (greater than - after Jan 1, 2023)
          _lt: "2024-01-01T00:00:00Z" # (less than - before Jan 1, 2024)
        }
      },
      blockchain: ethereum,
      order: {blockTimestamp: DESC}
    }
  ) {
    TokenTransfer {
      blockchain
      formattedAmount
      blockTimestamp
      tokenAddress
      tokenNft {
        metaData {
          name
        }
        contentValue {
          image {
            medium
          }
        }
      }
      tokenType
    }
  }
}

Get ERC20 Token Mints By A User in a Specified Period

You can fetch all ERC20 tokens minted during a specified period of time by a user, e.g. ipeciura.eth, across different chains, e.g. Ethereum, Base, Degen Chain, and other Airstack-supported chains, by using the TokenTransfers API:

Try Demo

Code

query MyQuery {
  TokenTransfers(
    input: {
      filter: {
        # Only get mints that are executed by the same user
        operator: {_eq: "ipeciura.eth"},
        # Mints are token transfers that has null address as `from`
        from: {_eq: "0x0000000000000000000000000000000000000000"},
        # Set this to the user that receive the token mints
        to: {_eq: "ipeciura.eth"},
        # Get only ERC20 tokens
        tokenType: {_eq: ERC20}
        # Specify time stamp (in 2022)
        blockTimestamp: {
          _gt: "2022-01-01T00:00:00Z", # (greater than - before Jan 1, 2022)
          _lt: "2023-01-01T00:00:00Z" # (less than - before Jan 1, 2023)
        }
      },
      blockchain: base,
      order: {blockTimestamp: DESC}
    }
  ) {
    TokenTransfer {
      blockchain
      formattedAmount
      blockTimestamp
      tokenAddress
      token {
        name
      }
    }
  }
}

Get Current Balance of Minted NFTs

Fetching

You can fetch the current NFT balances of minted NFTs, e.g. ipeciura.eth, across different chains, e.g. Ethereum, Base, Degen Chain, and other Airstack-supported chains, by using the TokenTransfers API:

Try Demo

Code

query MyQuery {
  TokenTransfers(
    input: {
      filter: {
        # Only get mints that are executed by the same user
        operator: {_eq: "ipeciura.eth"},
        # Mints are token transfers that has null address as `from`
        from: {_eq: "0x0000000000000000000000000000000000000000"},
        # Set this to the user that receive the token mints
        to: {_eq: "ipeciura.eth"},
        # Get only ERC721/1155 NFTs
        tokenType: {_in: [ERC1155, ERC721]}
      },
      order: {blockTimestamp: DESC},
      blockchain: ethereum
    }
  ) {
    TokenTransfer {
      blockTimestamp
      type
      transactionHash
      tokenNft {
        contentValue {
          image {
            medium
          }
        }
      }
      token {
        name
        address
        type
        tokenBalances(input: {filter: {owner: {_eq: "ipeciura.eth"}}}) {
          formattedAmount
        }
      }
    }
  }
}

Formatting

To get the list of minted NFTs and their current balance in a flat array, use the following format function:

interface Token {
  name: string;
  type: string;
  address: string;
  tokenBalances: { formattedAmount?: string }[];
}

interface TokenTransfer {
  token: Token;
}

interface Data {
  TokenTransfers?: {
    TokenTransfer: TokenTransfer[];
  };
}

/**
 * @description Formats the NFT mints data.
 *
 * @example
 * import { fetchQuery } from "@airstack/node";
 *
 * const { data } = await fetchQuery(query, variables);
 * const res = formatFunction(data);
 *
 * @param {Data} data - The data result from NFT mints query.
 * @returns {Object[]} An array of formatted minted NFTs' current balance
 */
const formatFunction = (data: Data) =>
  data?.TokenTransfers?.TokenTransfer?.map(({ token }) => {
    const { name, type, address, tokenBalances } = token;
    const formattedAmount = tokenBalances[0]?.formattedAmount ?? 0;
    return { name, type, address, formattedAmount };
  })?.filter(
    (arr, index, self) =>
      index === self.findIndex((t) => t.address === arr.address)
  );

With this format function, you will get the following result that you can directly add to your application:

[
  {
    "name": "Unveiling Airstack's Onchain Graph",
    "type": "ERC721",
    "address": "0xd3b4de0d85c44c57993b3b18d42b00de81809eea",
    "formattedAmount": 1
  },
  {
    "name": "MIAMI ESPORTS",
    "type": "ERC721",
    "address": '0x15b120343928019be964a353cf4f7dae474fb579",
    "formattedAmount": 1
  }
]

Get Current Balance of Minted ERC20 Tokens

Fetching

You can fetch the current ERC20 token balances of minted ERC20 tokens that are still hold by a user, e.g. ipeciura.eth, across different chains, e.g. Ethereum, Base, Degen Chain, and other Airstack-supported chains, by using the TokenTransfers API:

Try Demo

Code

query MyQuery {
  TokenTransfers(
    input: {
      filter: {
        # Only get mints that are executed by the same user
        operator: {_eq: "ipeciura.eth"},
        # Mints are token transfers that has null address as `from`
        from: {_eq: "0x0000000000000000000000000000000000000000"},
        # Set this to the user that receive the token mints
        to: {_eq: "ipeciura.eth"},
        # Get only ERC20 tokens
        tokenType: {_eq: ERC20}
      },
      order: {blockTimestamp: DESC},
      blockchain: ethereum}
  ) {
    TokenTransfer {
      blockTimestamp
      type
      transactionHash
      token {
        name
        address
        tokenBalances(input: {filter: {owner: {_eq: "ipeciura.eth"}}}) {
          formattedAmount
        }
      }
    }
  }
}

Formatting

To get the list of minted ERC20 tokens and their current balance in a flat array, use the following format function:

interface Token {
  name: string;
  address: string;
  tokenBalances: { formattedAmount?: string }[];
}

interface TokenTransfer {
  token: Token;
}

interface Data {
  TokenTransfers?: {
    TokenTransfer: TokenTransfer[];
  };
}

/**
 * @description Formats the ERC20 token mints data.
 *
 * @example
 * import { fetchQuery } from "@airstack/node";
 *
 * const { data } = await fetchQuery(query, variables);
 * const res = formatFunction(data);
 *
 * @param {Data} data - The data result from ERC20 token mints query.
 * @returns {Object[]} An array of formatted minted ERC20 tokens' current balance
 */
const formatFunction = (data: Data) =>
  data?.TokenTransfers?.TokenTransfer?.map(({ token }) => {
    const { name, address, tokenBalances } = token;
    const formattedAmount = tokenBalances[0]?.formattedAmount ?? 0;
    return { name, address, formattedAmount };
  })?.filter(
    (arr, index, self) =>
      index === self.findIndex((t) => t.address === arr.address)
  );

With this format function, you will get the following result that you can directly add to your application:

[
  {
    "name": "Balancer B-stMATIC-STABLE RewardGauge Deposit",
    "address": "0x9928340f9e1aaad7df1d95e27bd9a5c715202a56",
    "formattedAmount": 0.9908239030713007
  },
  {
    "name": "Uniswap V2",
    "address": "0xadbf1854e5883eb8aa7baf50705338739e558e5b",
    "formattedAmount": 0
  }
  // Other minted ERC20 tokens
]

Developer Support

If you have any questions or need help regarding fetching token mints data into your application, please join our Airstack's Telegram group.

More Resources

Last updated

Was this helpful?