🎭Allow List

Learn how to use the Allow List Middleware to check whether a user is allowed to use your Frames.js Frames based on their Farcaster data.

Get Started

First, install the Airstack Frames SDK:

npm install @airstack/frames

Check User's Farcaster Followers Count

You can use the allowListFramesjsMiddleware to check if a user has certain number of followers by using the NUMBER_OF_FARCASTER_FOLLOWERS and specifying the criteria using one of the comparison operator offered by Airstack:

import { createFrames, Button } from "frames.js/next";
import {
  AllowListCriteriaEnum as AllowListCriteria,
  allowListFramesjsMiddleware as allowList,
} from "@airstack/frames";

const frames = createFrames();

const handleRequest = frames(
  async (ctx) => {
    // Use `ctx.isAllowed` to check if user is allowed or not
    // based on the Farcaster followers count
    console.log(ctx.isAllowed);
    return {
      image: (<div></div>),
      buttons: [],
    };
  },
  {
    middleware: [
      // Allow List Middleware
      allowList({
        apiKey: process.env.AIRSTACK_API_KEY as string,
        criteria: {
          or: [
            // Only allow those with greater than 100 followers
            [AllowListCriteria.NUMBER_OF_FARCASTER_FOLLOWERS, { _gte: 100 }],
          ],
        },
      }),
    ],
  }
);

Check If User Is Followed By Certain Farcaster User

You can use the allowListFramesjsMiddleware to check if a user is followed by a certain Farcaster user by using the FARCASTER_FOLLOWED_BY and specifying the fid of that certain Farcaster user:

import { createFrames, Button } from "frames.js/next";
import {
  AllowListCriteriaEnum as AllowListCriteria,
  allowListFramesjsMiddleware as allowList,
} from "@airstack/frames";

const frames = createFrames();

const handleRequest = frames(
  async (ctx) => {
    // Use `ctx.isAllowed` to check if user is allowed or not
    // based on the Farcaster followers count
    console.log(ctx.isAllowed);
    return {
      image: (<div></div>),
      buttons: [],
    };
  },
  {
    middleware: [
      // Allow List Middleware
      allowList({
        apiKey: process.env.AIRSTACK_API_KEY as string,
        criteria: {
          or: [
            // Only allow those who are followed by fid 1
            [AllowListCriteria.FARCASTER_FOLLOWED_BY, { fid: 1 }],
          ],
        },
      }),
    ],
  }
);

Check If User Is Following Certain Farcaster User

You can use the allowListFramesjsMiddleware to check if a user is following a certain Farcaster user by using the FARCASTER_FOLLOWED_BY and specifying the fid of that certain Farcaster user:

import { createFrames, Button } from "frames.js/next";
import {
  AllowListCriteriaEnum as AllowListCriteria,
  allowListFramesjsMiddleware as allowList,
} from "@airstack/frames";

const frames = createFrames();

const handleRequest = frames(
  async (ctx) => {
    // Use `ctx.isAllowed` to check if user is allowed or not
    // based on the Farcaster followers count
    console.log(ctx.isAllowed);
    return {
      image: (<div></div>),
      buttons: [],
    };
  },
  {
    middleware: [
      // Allow List Middleware
      allowList({
        apiKey: process.env.AIRSTACK_API_KEY as string,
        criteria: {
          or: [
            // Only allow those who are following fid 1
            [AllowListCriteria.FARCASTER_FOLLOWING, { fid: 1 }],
          ],
        },
      }),
    ],
  }
);

Check If User Is Following The Caster

You can use the allowListFramesjsMiddleware to check if a user is following the caster of the Frame by using the FARCASTER_FOLLOWING_CASTER:

import { createFrames, Button } from "frames.js/next";
import {
  AllowListCriteriaEnum as AllowListCriteria,
  allowListFramesjsMiddleware as allowList,
} from "@airstack/frames";

const frames = createFrames();

const handleRequest = frames(
  async (ctx) => {
    // Use `ctx.isAllowed` to check if user is allowed or not
    // based on the Farcaster followers count
    console.log(ctx.isAllowed);
    return {
      image: (<div></div>),
      buttons: [],
    };
  },
  {
    middleware: [
      // Allow List Middleware
      allowList({
        apiKey: process.env.AIRSTACK_API_KEY as string,
        criteria: {
          or: [
            // Only allow those who are following the caster
            [AllowListCriteria.FARCASTER_FOLLOWING_CASTER],
          ],
        },
      }),
    ],
  }
);

Developer Support

If you have any questions or need help regarding building Farcaster Frames with Airstack Frames.js Middleware, please join our Airstack's Telegram group.

More Resources

Last updated

#946:

Change request updated