Learn how to enable users to access certain features only if they have a Lens profile or a combination of Lens + other criteria such as a specific POAP or NFT.
provides easy-to-use APIs for enriching applications and integrating on-chain and off-chain data with .
In this tutorial, you will learn how to build token gating systems in your dapp that grant feature access to Lens profile(s) based on specific on-chain criteria.
In this guide you will learn how to use to:
Pre-requisites
An account (free)
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
React
yarn add @airstack/airstack-react
Node
yarn add @airstack/node
React
pnpm install @airstack/airstack-react
Node
pnpm install @airstack/node
pip install airstack asyncio
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 (loading) {
return <p>Loading...</p>;
}
if (error) {
return <p>Error: {error.message}</p>;
}
// Render your component using the data returned by the query
};
If the length of the data.TokenBalances.TokenBalance array is 0, then it implies that the user has no given NFT held.
Otherwise, the user have at least one of the given NFT and then can have the owner.socials to be checked further to confirm if the user has any Lens profile.
If owner.socials has length 0, then similarly the user has no Lens profile.
Otherwise, the user has Lens profile and can be given access to a the desired feature.
Gating only user(s) that have Lens Profile and POAP
You can implement token gating by checking whether users have both Lens profile and the given POAP:
If the length of the data.Poaps.Poap array is 0, then it implies that the user has no given POAP held.
Otherwise, the user have at least one of the given POAP and then can have the owner.socials to be checked further to confirm if the user has any Lens profile.
If owner.socials has length 0, then similarly the user has no Lens profile.
Otherwise, the user has that Lens profile and can be given access to a the desired feature.
Developer Support
More Resources
To access the Airstack APIs in other languages, you can use as your GraphQL endpoint.
đ¤ AI Natural Language
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.
If you have any questions or need help regarding token gating, please join our Airstack's group.