πŸšͺToken Gating

Learn how to enable users to access certain features only if they follow a certain user or have common followers with a given user.

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

Table Of Contents

In this guide you will learn how to use Airstack to:

Pre-requisites

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.

Gating Only User(s) That Follows A Given User

You can build a token-gating system that gates only users that follow a given user by checking if user A is following a given user B.

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

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

Try Demo

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 either Lens or Farcaster, then it will appear as a response in the Following array as shown in the sample response and thus should be given feature access.

Otherwise, betashop.eth will be considered an not be given any feature access.

Gating Only User(s) That Have Common Followers

You can build a token-gating system that gates only users that have common followers with a given user.

This can be done by fetching the intersection of following between two or more users providing either 0x addresses, ENS names, Lens profiles, or Farcasters.

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

Try Demo

Code

query MyQuery {
  SocialFollowings( # user A: betashop.eth
    input: {filter: {identity: {_eq: "betashop.eth"}}, blockchain: ALL, limit: 200}
  ) {
    Following {
      followingAddress {
        socialFollowings( # user B: ipeciura.eth
          input: {filter: {identity: {_eq: "ipeciura.eth"}}, limit: 200}
        ) {
          Following {
            followingAddress {
              socials {
                fnames
                profileName
                profileTokenId
                profileTokenIdHex
                userId
                userAssociatedAddresses
              }
            }
          }
        }
      }
    }
  }
}

If betashop.eth has common following ipeciura.eth on either Lens or Farcaster, then it will appear as a response in the innermost Following array as shown in the sample response and thus should be given feature access.

Otherwise, betashop.eth will be considered an not be given any feature access.

Developer Support

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

More Resources

Last updated

Was this helpful?