Skip to content

Latest commit

 

History

History
97 lines (79 loc) · 2.33 KB

fids.md

File metadata and controls

97 lines (79 loc) · 2.33 KB
description
Learn how to fetch FIDs data using Airstack Hubs API.

🗒️ FIDs

Get All FIDs

You can get all existing FIDs on Farcaster by using Airstack Hubs API with the code below:

{% tabs %} {% tab title="@farcaster/hub-nodejs" %}

import {
  Metadata,
  getSSLHubRpcClient,
} from "@farcaster/hub-nodejs";
import { config } from "dotenv";

config();

const client = getSSLHubRpcClient("hubs-grpc.airstack.xyz");

client.$.waitForReady(Date.now() + 5000, async (e) => {
  if (e) {
    console.error(`Failed to connect to the gRPC server:`, e);
    process.exit(1);
  } else {
    console.log(`Connected to the gRPC server`);
    const metadata = new Metadata();
    // Provide API key here
    metadata.add("x-airstack-hubs", process.env.AIRSTACK_API_KEY as string);

    // Fetch all FIDs
    const castsResult = await client.getFids({}, metadata);
    console.log(castsResult?.value);
    // After everything, close the RPC connection
    client.close();
  }
});

{% endtab %}

{% tab title="axios" %}

import axios from "axios";
import { config } from "dotenv";

config();

const main = async () => {
  const server = "https://hubs.airstack.xyz";
  try {
    const response = await axios.get(`${server}/v1/fids`, {
      headers: {
        "Content-Type": "application/json",
        // Provide API key here
        "x-airstack-hubs": process.env.AIRSTACK_API_KEY as string,
      },
    });
  
    console.log(response);
  
    console.log(json);
  } catch (e) {
    console.error(e);
  }
}

main();

{% endtab %}

{% tab title="Response" %}

{
  "fids": [1, 2, 3, 4, 5, 6],
  "nextPageToken": "AAAnEA=="
}

{% endtab %} {% endtabs %}

Developer Support

If you have any questions or need help regarding integrating FIDs data using AIrstack Hubs API into your Farcaster app, please join our Airstack's Telegram group.

More Resources