๐Ÿ”ŽSearch Farcaster Users

Learn how to use Airstack to search for Farcaster users that fulfills the given filters or sort variables the API offered.

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 Farcaster Users Sorted By Social Capital Scores

You can use the Socials API to fetch all Farcaster users sorted by social capital scores by adding socialCapitalScore to the order field and set it to DESC value to sort in descending order:

Try Demo

Code

query MyQuery {
  Socials(
    input: {
      filter: {
        dappName: {_eq: farcaster}
      },
      blockchain: ethereum,
      order: {socialCapitalScore: DESC}, # Add this to sort by SCS
      limit: 200
    }
  ) {
    Social {
      profileName
      fid: userId
      custodyAddress: userAddress
      connectedAddresses {
        address
        blockchain
      }
      farcasterScore {
        farScore
      }
    }
  }
}

Get All Farcaster Users With Social Capital Scores > X

You can use the Socials API to fetch all Farcaster users with social capital scores above certain number by using the socialCapitalScore input field and provide the X value to the _gt filter (for other comparators, check out here).

In the example below, X is 50:

If you would like to also sort the result by social capital score, simply add socialCapitalScore to the order field and set the value to DESC. To learn more how to do it, click here.

Try Demo

Code

query MyQuery {
  Socials(
    input: {
      filter: {
        dappName: {_eq: farcaster},
        socialCapitalScore: {_gt: 50} # greater than to 50
      },
      blockchain: ethereum,
      limit: 200
    }
  ) {
    Social {
      profileName
      fid: userId
      custodyAddress: userAddress
      connectedAddresses {
        address
        blockchain
      }
      farcasterScore {
        farScore
      }
    }
  }
}

Get All Farcaster Users Sorted By Social Capital Rank

You can use the Socials API to fetch all Farcaster users sorted by social capital rank by adding socialCapitalRank to the order field and set it to ASC value to sort in ascending order:

Try Demo

Code

query MyQuery {
  Socials(
    input: {
      # Order by social capital rank in ascending order
      order: {socialCapitalRank: ASC},
      filter: {
        dappName: {
          _eq: farcaster
        }
      },
      blockchain: ethereum
    }
  ) {
    Social {
      profileName
      fid: userId
      custodyAddress: userAddress
      connectedAddresses {
        address
        blockchain
      }
      farcasterScore {
        farScore
      }
    }
  }
}

Get All Farcaster Users With Social Capital Rank < X

You can use the Socials API to fetch all Farcaster users with social capital rank below certain value by using the socialCapitalRank input field and the _lte operator. If you prefer other comparator for your logic, you can use other available comparator that suits you need (check more here).

If you would like to also sort the result by social capital rank, simply add socialCapitalRank to the order field and set the value to ASC. To learn more how to do it, click here.

Try Demo

Code

query MyQuery {
  Socials(
    input: {
      filter: {
        dappName: {
          _eq: farcaster
        },
        socialCapitalRank: {
          _lte: 100 # less than or equal to 100
        }
      },
      blockchain: ethereum
    }
  ) {
    Social {
      profileName
      fid: userId
      custodyAddress: userAddress
      connectedAddresses {
        address
        blockchain
      }
      farcasterScore {
        farScore
      }
    }
  }
}

Get All Farcaster Users Starting With Given Words

You can fetch all Farcaster users that starts with given words by providing the regex pattern "^<given-words>" to the _regex operator in Socials API:

Try Demo

Code

query MyQuery {
  Socials(
    input: {
      filter: {
        # This regex pattern will search all Farcaster users
        # starting with "a"
        profileName: {_regex: "^a"},
        dappName: {_eq: farcaster}
      },
      blockchain: ethereum
    }
  ) {
    Social {
      dappName
      profileName
    }
  }
}

Get All Farcaster Users Containing Given Words

You can fetch all Farcaster users that contains given words by providing "<given-words>" directly to the _regex operator in Socials API:

Try Demo

Code

query MyQuery {
  Socials(
    input: {
      filter: {
        # This regex pattern will search all Farcaster users
        # containing "abc"
        profileName: {_regex: "abc"},
        dappName: {_eq: farcaster}
      },
      blockchain: ethereum
    }
  ) {
    Social {
      dappName
      profileName
    }
  }
}

Get All Farcaster Users That Has Certain Number of Letters

You can fetch all Farcaster users that has certain number of letters in its profile name by providing "^.{min_number_of_letters, max_number_of_letters}$" directly to the _regex operator in Socials API, where the minimum should always be less than or equal to the maximum:

Try Demo

Code

query MyQuery {
  Socials(
    input: {
      filter: {
        # This regex pattern search all Farcaster users that have 1-3
        # letters in its profile name
        profileName: {_regex: "^.{1,3}$"}
        dappName: {_eq: farcaster}
      },
      blockchain: ethereum
    }
  ) {
    Social {
      dappName
      profileName
    }
  }
}

Developer Support

If you have any questions or need help regarding searching for Farcaster users, please join our Airstack's Telegram group.

More Resources

Last updated

Was this helpful?