Cover photo

AlfaFrens Subscriber Management with Google Sheets and Airstack

Automating FID Lookups: Streamlining Supporter Data and ETH Address Retrieval for AlfaFrens Users

Jordan Lyall

Jordan Lyall

Intro

Are you as obsessed with AlfaFrens as I am? If you’re managing a channel, knowing who your supporters are—and being able to reward your most loyal stakers—is crucial. But until now, efficiently gathering useful information and obtaining Ethereum addresses for your devoted followers has been a major hurdle.

Fear not! I've developed a streamlined method to automatically retrieve detailed subscriber data, including ETH addresses, directly from FIDs. This guide will walk you through setting up a system that not only personalizes your interactions but also makes rewarding your valuable supporters a breeze.

post image

Sign Up for Airstack

If you've been exploring or building within the Farcaster ecosystem, you're probably aware that Airstack is a treasure trove of tools, APIs, and documentation. It's invaluable, especially since it provides essential data that AlfaFrens doesn’t yet offer. Here’s how to get started:

  • Create an Account: Head over to the Airstack website and sign up. Simple and straightforward.

  • Secure an API Key: While setting up your account, request an API key. This key is crucial as it will bridge Airstack’s data with your Google Sheets, unlocking new depths of subscriber insights. Keep this key secure and handy.

With your Airstack account ready, you're set to revolutionize how you manage and engage with your subscribers. Next, we'll dive into extracting your subscriber data and setting the stage for automation.

Exporting Data from AlfaFrens

AlfaFrens simplifies the process of exporting the FIDs of your subscribers and stakers directly from a Farcaster frame.

Here’s how to do it:

  1. Start Exploring: Visit the specific Farcaster frame linked here and click "Start Exploring"

  2. Select Data Type: Choose to export data for either "subs" or "stakers".

  3. Check Status and Export: Click "Check status" to see if the data is ready. Once it is, a link will appear allowing you to download the data as a CSV file.

With your data in hand, you’re ready to move on to the exciting part—setting up Google Sheets for automation and bringing this data to life.

Automating Data Retrieval Inside Google Sheets

It's time to turn these FIDs into actionable insights. Google Sheets, coupled with Google Apps Script, offers a powerful platform to automate this data transformation. Here’s how to get it all set up:

  1. Prepare Your Spreadsheet:

    • Open Google Sheets and start a new spreadsheet.

    • Name your spreadsheet for easy identification (e.g., "AlfaFrens Subscribers").

  2. Set Up Google Apps Script:

    • Click on Extensions in the menu, then select Apps Script.

    • Delete any pre-existing code in the script editor that opens up.

    • Copy and paste the script provided below or on Github (ensure you replace placeholders like YOUR_AIRSTACK_API_KEY with actual values from your Airstack account). This script will pull additional data like Ethereum addresses and profile names based on the FIDs.

    • Save and name your project (e.g., "AF Sub Data Fetch").

  3. Import Your CSV Data:

    • Return to your Google Sheet.

    • Bring in the FIDs from the CSV file you downloaded into the spreadsheet. Ensure that the FIDs are in the first column.

  4. Execute the Script:

    • Under the Extensions menu, you should now see a custom menu item titled "️ " or similar, based on your script setup. If you don't see it, you may need to refresh.

    • Click this menu and select Update to run your script.

    • The script will execute, populating your spreadsheet with rich data fetched via Airstack.

  5. Verify and Utilize the Data:

    • Once the script completes, your sheet will be filled with information about each subscriber like user name, follow count, follower count, and a link to their Warpcast account. If a user has an attached ENS domain, you'll find that here. If not, you can grab one of their additional connected Ethereum addresses.

    • Use this data to enhance your interactions, tailor your content, or directly send rewards and communications.

Automation Script

function updateETHAddresses() {
  // Access the active sheet
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  
  // Define the range of user IDs to update
  const range = sheet.getRange("A2:A" + sheet.getLastRow());
  const fids = range.getValues();
  
  // Set API credentials and endpoint
  const apiKey = 'YOUR_AIRSTACK_API_KEY';
  const url = 'https://api.airstack.xyz/gql';

  // Iterate over each user ID to fetch and update information
  fids.forEach((row, index) => {
    // GraphQL query for user's social profile and associated Ethereum addresses
    const userQuery = `query MyQuery($userId: String, $blockchain: Blockchain!) {
      Socials(input: {filter: {userId: {_eq: $userId}}, blockchain: $blockchain}) {
        Social {
          profileName
          followerCount
          followingCount
          isFarcasterPowerUser
          userAssociatedAddresses
        }
      }
    }`;

    // Define variables for the GraphQL query
    const userVariables = {
      userId: row[0].toString(),
      blockchain: "ethereum"
    };

    // Set options for HTTP request
    const userOptions = {
      'method' : 'post',
      'contentType': 'application/json',
      'headers': {
        'Authorization': 'Bearer ' + apiKey
      },
      'payload' : JSON.stringify({
        query: userQuery,
        variables: userVariables
      }),
      'muteHttpExceptions': true
    };

    // Fetch user data from Airstack API
    const userResponse = UrlFetchApp.fetch(url, userOptions);
    const userJson = JSON.parse(userResponse.getContentText());
    
    // Check if user data is available and process it
    if (userJson.data && userJson.data.Socials && userJson.data.Socials.Social && userJson.data.Socials.Social.length > 0) {
      const social = userJson.data.Socials.Social[0];
      const profileName = social.profileName || "";
      const profileUrl = profileName ? `https://warpcast.com/${encodeURIComponent(profileName)}` : "";
      const profileLink = profileName ? `=HYPERLINK("${profileUrl}", "${profileName}")` : "";
      const followerCount = social.followerCount || "";
      const followingCount = social.followingCount || "";
      const isPowerUser = social.isFarcasterPowerUser ? "Yes" : "";
      const addresses = social.userAssociatedAddresses || [];

      // Fetch ENS domains for the Ethereum addresses
      const ensQuery = `query MyQuery($address: [Identity!]) {
        Domains(input: {filter: {owner: {_in: $address}}, blockchain: ethereum}) {
          Domain {
            name
          }
        }
      }`;

      // Set options for HTTP request to fetch ENS domains
      const ensOptions = {
        'method' : 'post',
        'contentType': 'application/json',
        'headers': {
          'Authorization': 'Bearer ' + apiKey
        },
        'payload' : JSON.stringify({
          query: ensQuery,
          variables: { address: addresses.length > 0 ? addresses : [""] }
        }),
        'muteHttpExceptions': true
      };

      // Fetch ENS domain names
      const ensResponse = UrlFetchApp.fetch(url, ensOptions);
      const ensJson = JSON.parse(ensResponse.getContentText());
      const ensDomain = ensJson.data && ensJson.data.Domains && ensJson.data.Domains.Domain && ensJson.data.Domains.Domain.length > 0
                        ? ensJson.data.Domains.Domain[0].name : "";

      // Update sheet with fetched data
      sheet.getRange("B" + (index + 2)).setFormula(profileLink);
      sheet.getRange("C" + (index + 2)).setValue(followerCount);
      sheet.getRange("D" + (index + 2)).setValue(followingCount);
      sheet.getRange("E" + (index + 2)).setValue(isPowerUser);
      sheet.getRange("F" + (index + 2)).setValue(ensDomain);
      sheet.getRange("G" + (index + 2)).setValue(addresses.join(", "));
    } else {
      // Handle cases where no data is found
      sheet.getRange(index + 2, 2, 1, 6).setValues([["", "", "", "", "", ""]]);
    }
  });
}

/**
 * Adds a custom menu to the Google Sheet on open, facilitating the execution of the update function.
 */
function onOpen() {
  const ui = SpreadsheetApp.getUi();
  ui.createMenu('⚡️⚡️⚡️')
      .addItem('Update', 'updateETHAddresses')
      .addToUi();
}

Conclusion: A Smarter Way to Manage Your AF Supporters

You're now equipped to manage your subscribers and stakers more effectively, personalize interactions, and reward your community in meaningful ways.

Was this helpful? Stay tuned for more tips and strategies:

GramajoFarcaster
Gramajo
Commented 1 year ago

Is there a way to get the wallets from all of our subscribers?

ZenigameFarcaster
Zenigame
Commented 1 year ago
GramajoFarcaster
Gramajo
Commented 1 year ago

Thank you! 5000 $FOMO

Ξ2T 🏰Farcaster
Ξ2T 🏰
Commented 1 year ago
Christina BorrowLucid | ChonesFarcaster
Christina BorrowLucid | Chones
Commented 1 year ago

I want to join @kbc 's channel/group/thing, but am having operator error downloading the damn thing :/ Which means I loose patience and start doing other things...

kbcFarcaster
kbc
Commented 1 year ago

@0xfran might help

stellabelle 🔪Farcaster
stellabelle 🔪
Commented 1 year ago

How do i extract wallet addresses from my @alfafrens subscribers? Is there an easy way? @rjs

Ryan J. ShawFarcaster
Ryan J. Shaw
Commented 1 year ago

Right now @jordanlyall seems to have the best option

stellabelle 🔪Farcaster
stellabelle 🔪
Commented 1 year ago

thanks 10 $DEGEN

Jordan LyallFarcaster
Jordan Lyall
Commented 1 year ago

online onchain inframe

Jordan LyallFarcaster
Jordan Lyall
Commented 1 year ago

moisturized focused flourishing

Tracyit 🥰Farcaster
Tracyit 🥰
Commented 1 year ago

I liked your first cast, but I like this one even better lol

₿odaciouspiratΞFarcaster
₿odaciouspiratΞ
Commented 1 year ago

extremely unbothered

Ese 🌳Farcaster
Ese 🌳
Commented 1 year ago

Yes

carlosFarcaster
carlos
Commented 1 year ago

hey! gm i remember you shared a script to pull fid´s verified addresses, but cant find it. mind sharing it? thanks!

Jordan LyallFarcaster
Jordan Lyall
Commented 1 year ago

hey, no problem. It's not perfect, but it gets the job done. https://jordanlyall.com/alfafrens-subscribers-airstack

carlosFarcaster
carlos
Commented 1 year ago

<3 150 $DEGEN

₿odaciouspiratΞFarcaster
₿odaciouspiratΞ
Commented 1 year ago

based

Jordan LyallFarcaster
Jordan Lyall
Commented 1 year ago

This week I built a tool that turns FIDs into rich user profiles + ETH addresses using @airstack.eth right inside Google Sheets A great use case is to track and reward your @alfafrens subs and stakers Here’s the plugin and step-by-step instructions 🫂 https://jordanlyall.com/alfafrens-subscribers-airstack

Toady Hawk, Pro CasterFarcaster
Toady Hawk, Pro Caster
Commented 1 year ago

Dope.

Jordan LyallFarcaster
Jordan Lyall
Commented 1 year ago

@toadyhawk.eth ⠀ 40 $degen

SQXFarcaster
SQX
Commented 1 year ago

ABB always be building. 🍖 x 50

Jordan LyallFarcaster
Jordan Lyall
Commented 1 year ago

👑

Ashira 🎩🫂🍖🍔💃🏼Farcaster
Ashira 🎩🫂🍖🍔💃🏼
Commented 1 year ago

Woah thank you!

Mistershot🎩Farcaster
Mistershot🎩
Commented 1 year ago

I have a problem on this step: Set Up Google Apps Script: Click on Extensions in the menu, then select Apps Script. I can't find the Extensions tab! Any help please? @jordanlyall dmed

Jordan LyallFarcaster
Jordan Lyall
Commented 1 year ago

Maybe you're on a version of Google Apps that blocks certain things? Like a work account?

Mistershot🎩Farcaster
Mistershot🎩
Commented 1 year ago

Oh this step is on google sheets??

Sasha BarrieFarcaster
Sasha Barrie
Commented 1 year ago

Okay, I’ll get on alfafriends now. 🙄🫡🤣

Jordan LyallFarcaster
Jordan Lyall
Commented 1 year ago

@kapuster ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ 40 $degen

Mad Jack 🎩 Farcaster
Mad Jack 🎩
Commented 1 year ago

Super handy 👌

Jordan LyallFarcaster
Jordan Lyall
Commented 1 year ago

@jsheps ⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀ 60 $degen

Warpcast BotFarcaster
Warpcast Bot
Commented 1 year ago

🔫 Moneygun Summary for @jordanlyall Success: 35 users Failed: 1 users Tip per user: 20

Jordan LyallFarcaster
Jordan Lyall
Commented 1 year ago

I wrote a plugin for Google Sheets that turns FIDs into rich user profiles + ETH addresses using @airstack.eth Track and reward your AlfaFrens supporters the easy way. Here’s the plugin and step-by-step instructions 🫂 https://paragraph.xyz/@jordanlyall/alfafrens-subscribers-airstack

Ese 🌳Farcaster
Ese 🌳
Commented 1 year ago

Nice build!!

Ese 🌳Farcaster
Ese 🌳
Commented 1 year ago

111 $degen

inway2deep🎩🍖🌈 🐘Farcaster
inway2deep🎩🍖🌈 🐘
Commented 1 year ago

Nicely done ser 19 $DEGEN

PiyushFarcaster
Piyush
Commented 1 year ago

yo man this is super cool!

Jordan LyallFarcaster
Jordan Lyall
Commented 1 year ago

🫂

Aditya TakFarcaster
Aditya Tak
Commented 1 year ago

This is awesome 🙌

tomuFarcaster
tomu
Commented 1 year ago

this is great Jordan

Jordan LyallFarcaster
Jordan Lyall
Commented 1 year ago

Thanks Tomu!

vijayFarcaster
vijay
Commented 1 year ago

222 $DEGEN

BaseFrens Ⓜ️Farcaster
BaseFrens Ⓜ️
Commented 1 year ago

100 $DEGEN Are you pulling the custody address or the associated address? I might use for a giveaway.

Jordan LyallFarcaster
Jordan Lyall
Commented 1 year ago

cheers. It pulls main ENS and then all attached wallets as wetll

Anemale🎩↑🔵ツFarcaster
Anemale🎩↑🔵ツ
Commented 1 year ago

you are the best Jordan thank you so much

GarrettFarcaster
Garrett
Commented 1 year ago

great tool! super useful

AlfaFrens Subscriber Management with Google Sheets and Airstack