🎉Hub Events

Learn how to fetch Hub events data using Airstack Hubs API.

Get Specific Event By ID

You can get an event by its Id to the Hub by using Airstack Hubs API with the code below:

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 event data with `getEvent`
    const eventRes = await client.getEvent(
      { id: 421699585773568 },
      metadata
    );
    console.log(eventRes.value);
    // After everything, close the RPC connection
    client.close();
  }
});

Get All Events From Hubs

You can get all events from the Hub by using Airstack Hubs API with the code below:

Hubs prune events older than 3 days, so not all historical events can be fetched via this API.

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/events?from_event_id=350909155450880`, {
      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();

Developer Support

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

More Resources

Last updated