🧩Moxie Fan Token Balances

Learn how to fetch user's Fan Token portfolio balances across all their wallets and vesting contracts. In addition, you will also learn how you can setup Fan Token gating for your project/application.

Table Of Contents

Pre-requisites

  • An Airstack API key. To access this, you'll need to hold at least 1 /airstack Channel Fan Token.

  • 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.

Get User's Fan Token Balances By Wallet Address

You can get a user's Fan Token portfolio balances by using the MoxieUserPortfolio API and inputting the user's wallet address in walletAddress input:

Try Demo

Code

query MyQuery {
  MoxieUserPortfolios(
    input: {
      filter: {
        walletAddress: {
          _eq: "0xd7029bdea1c17493893aafe29aad69ef892b8ff2"
        }
      }
    }
  ) {
    MoxieUserPortfolio {
      fanTokenSymbol
      fanTokenAddress
      fanTokenName
      amount: totalUnlockedAmount
    }
  }
}

Get User's Fan Token Balances By FID

You can get a user's Fan Token portfolio balances by using the MoxieUserPortfolio API and inputting the user's FID in fid input:

Try Demo

Code

query MyQuery {
  MoxieUserPortfolios(
    input: {
      filter: {
        fid: {_eq: "3"}
      }
    }
  ) {
    MoxieUserPortfolio {
      fanTokenAddress
      fanTokenName
      fanTokenSymbol
      amount: totalUnlockedAmount
    }
  }
}

Check If Certain User Hold Certain Fan Token

You can check if a certain user hold a certain Fan Token in their portfolio balance by using the MoxieUserPortfolio API and inputting the user's wallet to the walletAddress input and the Fan Token symbol to the fanTokenSymbol input:

Alternatively, you can also use fid and fanTokenAddress to specify the user and Fan Token input, respectively.

Try Demo

Code

query GetPortfolioInfo {
  MoxieUserPortfolios(
    input: {
      filter: {
        walletAddress: {
          # user's wallet address
          _eq: "0xd7029bdea1c17493893aafe29aad69ef892b8ff2"
        },
        fanTokenSymbol: {
          # Fan Token to check, symbol will be based on types:
          # - User: fid:<FID>
          # - Channel: cid:<CHANNEL-ID>
          # - Network: id:farcaster
          _eq: "fid:3"
        }
      }
    }
  ) {
    MoxieUserPortfolio {
      amount: totalUnlockedAmount
    }
  }
}

Developer Support

If you have any questions or need help regarding fetching Farcaster user's Moxie Fan Token portfolio data, please join our Airstack's Telegram group.

More Resources

Last updated

Was this helpful?