description | layout | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 Farcaster.
In this guide you will learn how to use Airstack to:
If you are using JavaScript/TypeScript or Python, Install the Airstack SDK:
{% tabs %} {% tab title="npm" %} React
npm install @airstack/airstack-react
Node
npm install @airstack/node
{% endtab %}
{% tab title="yarn" %} React
yarn add @airstack/airstack-react
Node
yarn add @airstack/node
{% endtab %}
{% tab title="pnpm" %} React
pnpm install @airstack/airstack-react
Node
pnpm install @airstack/node
{% endtab %}
{% tab title="pip" %}
pip install airstack
{% endtab %} {% endtabs %}
Then, add the following snippets to your code:
{% tabs %} {% tab title="React" %}
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>;
}
};
{% endtab %}
{% tab title="Node" %}
import { init, fetchQuery } from "@airstack/node";
init("YOUR_AIRSTACK_API_KEY");
const query = `YOUR_QUERY`; // Replace with GraphQL Query
const { data, error } = await fetchQuery(query);
console.log("data:", data);
console.log("error:", error);
{% endtab %}
{% tab title="Python" %}
import asyncio
from airstack.execute_query import AirstackClient
api_client = AirstackClient(api_key="YOUR_AIRSTACK_API_KEY")
query = """YOUR_QUERY""" # Replace with GraphQL Query
async def main():
execute_query_client = api_client.create_execute_query_object(
query=query)
query_response = await execute_query_client.execute_query()
print(query_response.data)
asyncio.run(main())
{% endtab %} {% endtabs %}
To access the Airstack APIs in other languages, you can use https://api.airstack.xyz/gql as your GraphQL endpoint.
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, 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):
{% embed url="https://app.airstack.xyz/query/gxn0jQ0ADA" %} Show me if betashop.eth is following ipeciura.eth {% endembed %}
{% hint style="info" %}
If you need to check multiple users A simultaneously, then simply provide more identities into the identity
input in the socialFollowings
nested API.
{% endhint %}
{% tabs %} {% tab title="Query" %}
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
}
}
}
}
}
}
{% endtab %}
{% tab title="Response" %}
{
"data": {
"Wallet": {
"socialFollowings": {
"Following": [
{
"dappName": "farcaster", // following on Farcaster
"dappSlug": "farcaster_optimism",
"followingProfileId": "2602",
"followerProfileId": "602",
"followerAddress": {
"addresses": [
"0x66bd69c7064d35d146ca78e6b186e57679fba249",
"0xeaf55242a90bb3289db8184772b0b98562053559"
],
"socials": [
{
"dappName": "farcaster",
"profileName": "betashop.eth" // betashop.eth is following ipeciura.eth
},
],
"domains": [
{
"name": "jasongoldberg.eth"
},
{
"name": "betashop.eth"
}
]
}
}
]
}
}
}
}
{% endtab %} {% endtabs %}
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 given feature access.
Otherwise, betashop.eth
will be considered an not be given any feature access.
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, or Farcaster profiles.
For example, check if betashop.eth
(user A) has any common following ipeciura.eth
(user B):
{% embed url="https://app.airstack.xyz/query/I3UsTeLj1O" %} Show me common following of both betashop.eth and ipeciura.eth {% endembed %}
{% tabs %} {% tab title="Query" %}
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
}
}
}
}
}
}
}
}
{% endtab %}
{% tab title="Response" %}
{
"data": {
"SocialFollowings": {
"Following": [
{
"followingAddress": {
"socialFollowings": {
"Following": [
{
"followingAddress": {
"socials": [
{
"fnames": [
"nickcherry"
],
"profileName": "nickcherry", // this is common following
"userId": "145",
"userAssociatedAddresses": [
"0x1692101d7b84bf8ed8d828e44e55a8ca9a242bc4",
"0x3a8a1f045cd4f7246c6b3a78861269cc6065433a"
]
}
]
}
}
]
}
}
},
{
"followingAddress": {
"socialFollowings": {
"Following": [] // Followed by betashop.eth, but isn't followed by ipeciura
}
}
}
]
}
}
}
{% endtab %} {% endtabs %}
If betashop.eth
has common following ipeciura.eth
on 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.
If you have any questions or need help creating social following token gating, please join our Airstack's Telegram group.