📞Recommendation Users

Learn how to get recommended followers for Lens profiles based on on-chain insights from token transfers, POAPs, NFTS, token holder combinations, and Lens & Farcaster social followers/following.

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 (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.

Get Recommendation Follows For Lens Profile(s) Based on Token Transfers

To get recommendations by token transfers, simply fetch all token transfers that is received and sent from the Lens profile(s):

Try Demo

Show recommendations by token transfers for lens/@bradorbradley

Code

query GetRecommendationsByTokenTransfers {
  ethereum: TokenTransfers(
    input: {
      filter: {
        _or: {
          from: { _in: ["lens/@bradorbradley"] }
          to: { _in: ["lens/@bradorbradley"] }
        }
      }
      blockchain: ethereum
      limit: 50
    }
  ) {
    TokenTransfer {
      from {
        addresses
        socials(input: { filter: { dappName: { _in: lens } } }) {
          userId
          profileName
        }
      }
      to {
        addresses
        socials(input: { filter: { dappName: { _in: lens } } }) {
          userId
          profileName
        }
      }
    }
  }
  polygon: TokenTransfers(
    input: {
      filter: {
        _or: {
          from: { _in: ["lens/@bradorbradley"] }
          to: { _in: ["lens/@bradorbradley"] }
        }
      }
      blockchain: polygon
      limit: 50
    }
  ) {
    TokenTransfer {
      from {
        addresses
        socials(input: { filter: { dappName: { _in: lens } } }) {
          userId
          profileName
        }
      }
      to {
        addresses
        socials(input: { filter: { dappName: { _in: lens } } }) {
          userId
          profileName
        }
      }
    }
  }
  base: TokenTransfers(
    input: {
      filter: {
        _or: {
          from: { _in: ["lens/@bradorbradley"] }
          to: { _in: ["lens/@bradorbradley"] }
        }
      }
      blockchain: base
      limit: 50
    }
  ) {
    TokenTransfer {
      from {
        addresses
        socials(input: { filter: { dappName: { _in: lens } } }) {
          userId
          profileName
        }
      }
      to {
        addresses
        socials(input: { filter: { dappName: { _in: lens } } }) {
          userId
          profileName
        }
      }
    }
  }
}

Get Recommendation Follows For Lens Profile(s) Based on POAPs

To get recommendations by POAPs, first fetch all POAPs that is owned by the Lens profile(s):

Try Demo

Show POAPs owned by lens/@bradorbradley

Code

query POAPsOwnedByLensProfiles {
  Poaps(
    input: {
      filter: { owner: { _in: ["lens/@bradorbradley"] } }
      blockchain: ALL
    }
  ) {
    Poap {
      eventId
      poapEvent {
        eventName
        eventURL
        startDate
        endDate
        country
        city
        contentValue {
          image {
            extraSmall
            large
            medium
            original
            small
          }
        }
      }
    }
    pageInfo {
      nextCursor
      prevCursor
    }
  }
}

With the response, you can compile the eventIds as an array that can be forwarded as an input for the next query.

The next query for recommending follows based on POAPs will be fetching all the holders of the POAP with the eventIds in the array:

Try Demo

Show follow recommendations based on POAP event IDs 47553, 80122, and 37964

Code

query GetAllAddressesSocialsAndENSOfPOAP {
  Poaps(
    input: {
      filter: { eventId: { _in: ["47553", "80122", "37964"] } }
      blockchain: ALL
      limit: 200
    }
  ) {
    Poap {
      owner {
        identity
        socials(input: { filter: { dappName: { _eq: lens } } }) {
          profileName
          userId
        }
      }
    }
  }
}

The follow recommendation will provide a list of Lens profiles with the Lens profile name from the profileName field.

Get Recommendation Follows For Lens Profile(s) Based on NFTs

To get recommendations by NFTs, first fetch all NFTs that is owned by the Lens profile(s) on both Ethereum, Polygon, and Base:

Try Code

Code

query GetNFTs {
  ethereum: TokenBalances(
    input: {
      filter: {
        owner: { _in: ["lens/@bradorbradley"] }
        tokenType: { _in: [ERC1155, ERC721] }
      }
      blockchain: ethereum
      limit: 200
    }
  ) {
    TokenBalance {
      tokenAddress
    }
  }
  polygon: TokenBalances(
    input: {
      filter: {
        owner: { _in: ["lens/@bradorbradley"] }
        tokenType: { _in: [ERC1155, ERC721] }
      }
      blockchain: polygon
      limit: 200
    }
  ) {
    TokenBalance {
      tokenAddress
    }
  }
  base: TokenBalances(
    input: {
      filter: {
        owner: { _in: ["lens/@bradorbradley"] }
        tokenType: { _in: [ERC1155, ERC721] }
      }
      blockchain: base
      limit: 200
    }
  ) {
    TokenBalance {
      tokenAddress
    }
  }
}

With the response, you can compile the many tokenAddress as an array that can be forwarded as an input for the next query.

The next query for recommending follows based on NFTs will be fetching all the holders of the NFT with the eventIds in the array:

Try Demo

Code

query GetNFTHoldersAndImages {
  ethereum: TokenNfts(
    input: {
      filter: {
        address: {
          _in: [
            "0xf5806ba5635911aa1d2b7b794172d55c731ca860"
            "0xa4ed1befd956d4f444e7010955c3c06ffbd46ac7"
            "0x9d90669665607f08005cae4a7098143f554c59ef"
          ]
        }
      }
      blockchain: ethereum
    }
  ) {
    TokenNft {
      tokenBalances {
        owner {
          identity
          socials(input: { filter: { dappName: { _eq: lens } } }) {
            profileName
            userId
          }
        }
      }
    }
  }
  polygon: TokenNfts(
    input: {
      filter: {
        address: {
          _in: [
            "0xa71d227ffc872a4627e832f87b49ef46b29dd050"
            "0x5ef718b8360ef2b82fb971b50350913e2bad4783"
            "0xdeb053d41521672af06ba75d61be3364977461af"
          ]
        }
      }
      blockchain: polygon
    }
  ) {
    TokenNft {
      tokenBalances {
        owner {
          identity
          socials(input: { filter: { dappName: { _eq: lens } } }) {
            profileName
            userId
          }
        }
      }
    }
  }
  base: TokenNfts(
    input: {
      filter: {
        address: {
          _in: [
            "0xa71d227ffc872a4627e832f87b49ef46b29dd050"
            "0x5ef718b8360ef2b82fb971b50350913e2bad4783"
            "0xdeb053d41521672af06ba75d61be3364977461af"
          ]
        }
      }
      blockchain: base
    }
  ) {
    TokenNft {
      tokenBalances {
        owner {
          identity
          socials(input: { filter: { dappName: { _eq: lens } } }) {
            profileName
            userId
          }
        }
      }
    }
  }
}

The follow recommendation will provide a list of Lens profiles name from the profileName field.

Get Recommendation Follows For Lens Profile(s) Based on NFTs and POAPs Commonly Held

Fetching

You can fetch follow recommendations based on the common holder of a specific NFT and a specific POAP by providing the token contract address and the POAP event ID:

Try Demo

Code

query GetCommonHoldersOfNounsAndEthCC {
  TokenBalances(
    input: {filter: {tokenAddress: {_eq: "0x977e43ab3eb8c0aece1230ba187740342865ee78"}}, blockchain: ethereum, limit: 200}
  ) {
    TokenBalance {
      owner {
        poaps(input: {filter: {eventId: {_eq: "43882"}}}) {
          owner {
            socials(input: {filter: {dappName: {_eq: lens}}}) {
              profileName
              userId
              userAssociatedAddresses
            }
          }
        }
      }
    }
  }
}

All the common holders' Lens profile details will be returned inside the innermost owner.socials field.

Formatting

To get the list of all holders in a flat array, use the following format function:

const formatFunction = (data) =>
  data?.TokenBalances?.TokenBalance?.map(({ owner }) =>
    owner?.poaps?.map(({ owner }) => owner?.socials)
  )
    .filter(Boolean)
    .flat(2)
    .filter((social, index, array) => array.indexOf(social) === index) ?? [];

The final result will the the list of all common holders in an array:

[
  {
    "profileName": "lens/@westlakevillage",
    "userId": "0x8ec94086a724cbec4d37097b8792ce99cadcd520",
    "userAssociatedAddresses": ["0x8ec94086a724cbec4d37097b8792ce99cadcd520"]
  },
  {
    "profileName": "lens/@brad",
    "userId": "0x8ec94086a724cbec4d37097b8792ce99cadcd520",
    "userAssociatedAddresses": ["0x8ec94086a724cbec4d37097b8792ce99cadcd520"]
  },
  {
    "profileName": "lens/@bradorbradley",
    "userId": "0x8ec94086a724cbec4d37097b8792ce99cadcd520",
    "userAssociatedAddresses": ["0x8ec94086a724cbec4d37097b8792ce99cadcd520"]
  },
  {
    "profileName": "lens/@hanimourra",
    "userId": "0x8ec94086a724cbec4d37097b8792ce99cadcd520",
    "userAssociatedAddresses": ["0x8ec94086a724cbec4d37097b8792ce99cadcd520"]
  }
  // ...other token holders
]

Get Recommendation Follows For Lens Profile(s) Based on Lens Followers

Fetching

You can fetch follow recommendations based on the Lens followers of Lens profile(s) by fetching the list of Lens followers of the given Lens profile(s):

Try Demo

Code

query MyQuery {
  SocialFollowers(
    input: {
      filter: {
        dappName: { _eq: lens }
        identity: {
          _in: [
            "lens/@stani"
            "lens_id:0x24"
            "betashop.eth"
            "0xeaf55242a90bb3289dB8184772b0B98562053559"
          ]
        }
      }
      blockchain: ALL
      limit: 200
    }
  ) {
    Follower {
      followerAddress {
        addresses
        socials(input: { filter: { dappName: { _eq: lens } } }) {
          profileName
          profileTokenId
          profileTokenIdHex
        }
      }
      followingAddress {
        addresses
        domains {
          name
        }
        socials(input: { filter: { dappName: { _eq: lens } } }) {
          profileName
          profileTokenId
          profileTokenIdHex
        }
      }
    }
  }
}

Get Recommendation Follows For Lens Profile(s) Based on Farcaster Followers

Fetching

You can fetch follow recommendations based on the Farcaster followers of Lens profile(s) by fetching the list of Farcaster followers of the given Lens profile(s):

If the address that owns the given Lens profile NFT does not own any Farcaster account, then no Farcaster followers will exist and API response will be null.

Try Demo

Code

query MyQuery {
  SocialFollowers(
    input: {
      filter: {
        dappName: { _eq: farcaster }
        identity: { _in: ["lens/@vitalik"] }
      }
      blockchain: ALL
      limit: 200
    }
  ) {
    Follower {
      followerAddress {
        addresses
        socials(input: { filter: { dappName: { _eq: lens } } }) {
          profileName
          profileTokenId
          profileTokenIdHex
        }
      }
      followingAddress {
        addresses
        domains {
          name
        }
        socials(input: { filter: { dappName: { _eq: lens } } }) {
          profileName
          profileTokenId
          profileTokenIdHex
        }
      }
    }
  }
}

Get Recommendation Follows For Lens Profile(s) Based on Farcaster Following

Fetching

You can fetch follow recommendations based on the Farcaster following of Lens profile(s) by fetching the list of Farcaster followers of the given Lens profile(s):

If the address that owns the given Lens profile NFT does not own any Farcaster account, then no Farcaster following will exist and API response will be null.

Try Demo

Code

query MyQuery {
  SocialFollowings(
    input: {
      filter: {
        dappName: { _eq: farcaster }
        identity: { _in: ["lens/@vitalik"] }
      }
      blockchain: ALL
      limit: 200
    }
  ) {
    Following {
      followingAddress {
        addresses
        socials(input: { filter: { dappName: { _eq: lens } } }) {
          profileName
          profileTokenId
          profileTokenIdHex
        }
      }
      followerProfileId
      followerAddress {
        addresses
        domains {
          name
        }
        socials(input: { filter: { dappName: { _eq: lens } } }) {
          profileName
          profileTokenId
          profileTokenIdHex
        }
      }
      followingProfileId
    }
  }
}

Developer Support

If you have any questions or need help regarding building a recommendation engine, please join our Airstack's Telegram group.

More Resources

Last updated

Was this helpful?