💐Following

Learn how to fetch Web3 Social Following data and its various use cases and combinations.

Airstack provides easy-to-use APIs for enriching Web3 social applications with and integrating on-chain and off-chain data with Farcaster.

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.

Get All Following of 0x Address(es)

You can get the list of following data of user(s) by inputting an array of 0x address(es):

Try Demo

Show me all following of 0xeaf55242a90bb3289dB8184772b0B98562053559

Code

query MyQuery {
  SocialFollowings(
    input: {
      filter: {
        identity: { _in: ["0xeaf55242a90bb3289dB8184772b0B98562053559"] }
      }
      blockchain: ALL
      limit: 200
    }
  ) {
    Following {
      followingAddress {
        addresses
        domains {
          name
        }
        socials {
          dappName
          profileName
          profileTokenId
          profileTokenIdHex
          userId
          userAssociatedAddresses
        }
      }
      followingProfileId
      followerAddress {
        addresses
      }
      followerProfileId
      followerTokenId
    }
  }
}

Get All Following of ENS Domain(s)

You can get the list of following data of user(s) by inputting an array of ENS domain(s):

Try Demo

Show me all following of vitalik.eth

Code

query MyQuery {
  SocialFollowings(
    input: {
      filter: { identity: { _in: ["vitalik.eth"] } }
      blockchain: ALL
      limit: 200
    }
  ) {
    Following {
      followingAddress {
        addresses
        domains {
          name
        }
        socials {
          dappName
          profileName
          profileTokenId
          profileTokenIdHex
          userId
          userAssociatedAddresses
        }
      }
      followingProfileId
      followerAddress {
        domains {
          name
        }
      }
      followerProfileId
      followerTokenId
    }
  }
}

Get All Following of Farcaster User(s)

You can get the list of following data of user(s) by inputting an array of either Farcaster name or :

Try Demo

Show me all following of Farcaster user vitalik.eth

Code

query MyQuery {
  SocialFollowings(
    input: {
      filter: { identity: { _in: ["fc_fname:vitalik.eth"] } }
      blockchain: ALL
      limit: 200
    }
  ) {
    Following {
      followingAddress {
        addresses
        domains {
          name
        }
        socials {
          dappName
          profileName
          profileTokenId
          profileTokenIdHex
          userId
          userAssociatedAddresses
        }
      }
      followingProfileId
      followerAddress {
        addresses
        socials(input: { filter: { dappName: { _eq: farcaster } } }) {
          profileName
          profileTokenId
          profileTokenIdHex
        }
      }
      followerProfileId
      followerTokenId
    }
  }
}

Check If User A Is Following User B

This can be done by providing the user B's identiy either a 0x address, ENS, cb.id, or Farcaster on the Wallet top-level query's identity input and the user A's identities in the socialFollowings.

For example, check if betashop.eth (user A) is following ipeciura.eth (user B):

Try Demo

Show me if betashop.eth is following ipeciura.eth

Code

If you need to check multiple users A simultaneously, then simply provide more identities into the identity input in the socialFollowings nested API.

query isFollowing { # Top-level is User B's Identity (ipeciura.eth)
  Wallet(input: {identity: "ipeciura.eth", blockchain: ethereum}) {
    socialFollowings( # Here is User A's Identity (betashop.eth)
      input: {filter: {identity: {_in: ["betashop.eth"]}}}
    ) {
      Following {
        dappName
        dappSlug
        followingProfileId
        followerProfileId
        followerAddress {
          addresses
          socials {
            dappName
            profileName
          }
          domains {
            name
          }
        }
      }
    }
  }
}

If betashop.eth is following ipeciura.eth on Farcaster, then it will appear as a response in the Following array as shown in the sample response and thus should be classified as a known sender.

Otherwise, betashop.eth will be considered an unknown sender and should be classified as one in the UI.

Get The Most Recent Following of User(s)

You can get the list of most recent following of user(s):

Try Demo

Show me the most recent following of an array of users

Code

query MyQuery {
  SocialFollowings(
    input: {
      filter: {
        identity: {
          _in: [
            "lens/@stani"
            "lens_id:0x024"
            "fc_fname:dwr.eth"
            "fc_fid:3"
            "vitalik.eth"
            "0xeaf55242a90bb3289dB8184772b0B98562053559"
          ]
        }
      }
      blockchain: ALL
      limit: 200
      order: { followingSince: DESC }
    }
  ) {
    Following {
      followingAddress {
        addresses
        domains {
          name
        }
        socials {
          dappName
          profileName
          profileTokenId
          profileTokenIdHex
          userId
          userAssociatedAddresses
        }
      }
      followingProfileId
      followerAddress {
        addresses
        domains {
          name
        }
        socials {
          dappName
          profileName
          profileTokenId
          profileTokenIdHex
          userId
          userAssociatedAddresses
        }
      }
      followerProfileId
      followerTokenId
    }
  }
}

Get The Earliest Following of User(s)

You can get the list of the earliest following of user(s):

Try Demo

Show me the earliest following of an array of users

Code

query MyQuery {
  SocialFollowings(
    input: {
      filter: {
        identity: {
          _in: [
            "lens/@stani"
            "lens_id:0x024"
            "fc_fname:dwr.eth"
            "fc_fid:3"
            "vitalik.eth"
            "0xeaf55242a90bb3289dB8184772b0B98562053559"
          ]
        }
      }
      blockchain: ALL
      limit: 200
      order: { followingSince: ASC }
    }
  ) {
    Following {
      followingAddress {
        addresses
        domains {
          name
        }
        socials {
          dappName
          profileName
          profileTokenId
          profileTokenIdHex
          userId
          userAssociatedAddresses
        }
      }
      followingProfileId
      followerAddress {
        addresses
        domains {
          name
        }
        socials {
          dappName
          profileName
          profileTokenId
          profileTokenIdHex
          userId
          userAssociatedAddresses
        }
      }
      followerProfileId
      followerTokenId
    }
  }
}

Get Following of User(s) that has ENS Domain

You can get the list of all following of user(s) and check if they have any ENS domain:

Try Demo

Show me followings of an array of users that also have ENS domain

Code

query MyQuery {
  SocialFollowings(
    input: {filter: {identity: {_in: ["lens/@stani", "lens_id:0x024", "fc_fname:dwr.eth", "fc_fid:3", "vitalik.eth", "0xeaf55242a90bb3289dB8184772b0B98562053559"]}}, blockchain: ALL, limit: 200}
  ) {
    Following {
      followingAddress {
        addresses
        domains { # Show all domains owned by followers
          name
          isPrimary
        }
        socials {
          dappName
          profileName
          profileTokenId
          profileTokenIdHex
          userId
          userAssociatedAddresses
        }
      }
      followingProfileId
      followerAddress {
        addresses
        domains {
          name
        }
        socials {
          dappName
          profileName
          profileTokenId
          profileTokenIdHex
          userId
          userAssociatedAddresses
        }
      }
      followerProfileId
      followerTokenId
    }
  }
}

You can use the followingAddress.domains that will return an array to see if there's any domain owned by the following.

If the length of the followingAddress.domains array is non-zero, then the following has at least one ENS domain. Otherwise, it does not have any ENS domain.

Get Users that have a certain amount of Following

You can get the list of all users that have certain amount of following, e.g. at least 1000 following:

Try Demo

Show me all users that have at least 1000 following

Code

query MyQuery {
  Socials(
    input: {
      filter: { followingCount: { _gte: 1000 } }
      blockchain: ethereum
      limit: 200
    }
  ) {
    Social {
      dappName
      profileName
      profileTokenId
      profileTokenIdHex
      userId
      userAssociatedAddresses
      followingCount
    }
  }
}

Developer Support

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

More Resources

Last updated

Was this helpful?