πŸ”ŽSearch Lens Profiles

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

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

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 Lens Profiles

You can globally fetch all Lens profiles using the Socials API by specifying dappName to lens:

Try Demo

Show me all Lens profiles

Code

query MyQuery {
  Socials(
    input: {
      filter: { dappName: { _eq: lens } }
      blockchain: ethereum
      limit: 200
    }
  ) {
    Social {
      profileName
      userAssociatedAddresses
    }
    pageInfo {
      hasNextPage
      hasPrevPage
      nextCursor
      prevCursor
    }
  }
}

Get All Lens Profiles Starting With Given Words

You can fetch all Lens profiles that starts with given words by providing the regex pattern "^lens/@<given-words>" to the _regex operator in Socials API:

Try Demo

show me all Lens profiles starting with "a"

Code

query MyQuery {
  Socials(
    input: {
      filter: {
        # This regex pattern will search all Lens profile
        # starting with "a"
        profileName: {_regex: "^lens/@a"},
        dappName: {_eq: lens}
      },
      blockchain: ethereum
    }
  ) {
    Social {
      dappName
      profileName
    }
  }
}

Get All Lens Profiles Containing Given Words

You can fetch all Lens profiles 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 Lens profiles
        # containing "abc"
        profileName: {_regex: "abc"},
        dappName: {_eq: lens}
      },
      blockchain: ethereum
    }
  ) {
    Social {
      dappName
      profileName
    }
  }
}

Get All Lens Profiles That Has Certain Number of Letters

You can fetch all Lens profiles 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

show me all Lens profiles that has 3 letters or less

Code

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

Get All Lens Profiles Created In Specified Time

You can fetch all Lens profiles that are created in a specified time using the Socials API by specifying dappName to lens and profileCreatedAtBlockTimestamp to the desired block timestamp range:

Try Demo

Code

query MyQuery {
  Socials(
    input: {
      filter: {
        profileCreatedAtBlockTimestamp: {
          _gte: "2023-11-12T00:00:01Z"
          _lte: "2023-11-19T00:00:00Z"
        }
        dappName: { _eq: lens }
      }
      blockchain: ethereum
      limit: 200
    }
  ) {
    Social {
      profileName
      userAssociatedAddresses
      profileCreatedAtBlockNumber
    }
    pageInfo {
      hasNextPage
      hasPrevPage
      nextCursor
      prevCursor
    }
  }
}

Get The Latest Lens Profiles Created

You can fetch all the latest Lens profiles created using the Socials API by specifying dappName to lens and sorting profileCreatedAtBlockTimestamp in descending order:

Try Demo

Code

query MyQuery {
  Socials(
    input: {
      filter: { dappName: { _eq: lens } }
      blockchain: ethereum
      limit: 200
      order: { profileCreatedAtBlockTimestamp: DESC }
    }
  ) {
    Social {
      profileName
      userAssociatedAddresses
      profileCreatedAtBlockNumber
    }
    pageInfo {
      hasNextPage
      hasPrevPage
      nextCursor
      prevCursor
    }
  }
}

Get The Earliest Lens Profiles Created

You can fetch all the latest Lens profiles created using the Socials API by specifying dappName to lens and sorting profileCreatedAtBlockTimestamp in ascending order:

Try Demo

Code

query MyQuery {
  Socials(
    input: {
      filter: { dappName: { _eq: lens } }
      blockchain: ethereum
      limit: 200
      order: { profileCreatedAtBlockTimestamp: ASC }
    }
  ) {
    Social {
      profileName
      userAssociatedAddresses
      profileCreatedAtBlockNumber
    }
    pageInfo {
      hasNextPage
      hasPrevPage
      nextCursor
      prevCursor
    }
  }
}

Get The Most Followed Lens Profiles

You can fetch all the most followed Lens profiles using the Socials API by specifying dappName to lens and sorting followerCount in descending order:

Try Demo

Code

query MyQuery {
  Socials(
    input: {
      filter: { dappName: { _eq: lens } }
      blockchain: ethereum
      limit: 200
      order: { followerCount: DESC }
    }
  ) {
    Social {
      profileName
      userAssociatedAddresses
      followerCount
    }
    pageInfo {
      hasNextPage
      hasPrevPage
      nextCursor
      prevCursor
    }
  }
}

Get The Least Followed Lens Profiles

You can fetch all the least followed Lens profiles using the Socials API by specifying dappName to lens and sorting followerCount in ascending order:

Try Demo

Code

query MyQuery {
  Socials(
    input: {
      filter: { dappName: { _eq: lens } }
      blockchain: ethereum
      limit: 200
      order: { followerCount: ASC }
    }
  ) {
    Social {
      profileName
      userAssociatedAddresses
      followerCount
    }
    pageInfo {
      hasNextPage
      hasPrevPage
      nextCursor
      prevCursor
    }
  }
}

Get Lens Profiles That Is Following Others The Most

You can fetch all Lens profiles that is following other profiles the most using the Socials API by specifying dappName to lens and sorting followingCount in descending order:

Try Demo

Code

query MyQuery {
  Socials(
    input: {
      filter: { dappName: { _eq: lens } }
      blockchain: ethereum
      limit: 200
      order: { followingCount: DESC }
    }
  ) {
    Social {
      profileName
      userAssociatedAddresses
      followingCount
    }
    pageInfo {
      hasNextPage
      hasPrevPage
      nextCursor
      prevCursor
    }
  }
}

Get Lens Profiles That Is Following Others The Least

You can fetch all Lens profiles that is following other profiles the least using the Socials API by specifying dappName to lens and sorting followingCount in ascending order:

Try Demo

Code

query MyQuery {
  Socials(
    input: {
      filter: { dappName: { _eq: lens } }
      blockchain: ethereum
      limit: 200
      order: { followingCount: ASC }
    }
  ) {
    Social {
      profileName
      userAssociatedAddresses
      followingCount
    }
    pageInfo {
      hasNextPage
      hasPrevPage
      nextCursor
      prevCursor
    }
  }
}

Developer Support

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

More Resources

Last updated

Was this helpful?