👍Reactions

Learn how to fetch Reactions data using Airstack Hubs API.

Get Reactions By FID and Target Cast

You can get a reaction by its created FID and target cast by using Airstack Hubs API with the code below:

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

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 reaction data with `getReaction`
    const reactionsResult = await client.getReaction(
      {
        fid: 8150,
        reactionType: ReactionType.LIKE,
        targetCastId: {
          fid: 2,
          hash: castHashBytes,
        },
      },
      metadata,
    );
    
    if (reactionsResult.isOk()) {
      console.log(reactionsResult.value);
    } else {
      console.error("No reactions found: reactionsResult.error);
    }
    // After everything, close the RPC connection
    client.close();
  }
});

Get Reactions By FID

You can get all reactions by a specific FID by using Airstack Hubs API with the code below:

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

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 reactions data with `getReactionsByCast`
    const reactionsResult = await client.getReactionsByCast(
      {
        reactionType: ReactionType.LIKE,
        targetCastId: {
          fid: 2,
          hash: castHashBytes,
        },
      },
      metadata,
    );
    console.log(reactionsResult.value);
    // After everything, close the RPC connection
    client.close();
  }
});

Get Reactions By Cast

You can get all reactions by a specific cast hash by using Airstack Hubs API with the code below:

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

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 reaction data with `getReactionsByFid`
    const reactionsResult = await client.getReactionsByFid(
      { fid: 2, reactionType: ReactionType.LIKE },
      metadata,
    );
    console.log(reactionsResult.value);
    // After everything, close the RPC connection
    client.close();
  }
});

Get Reactions By Target Cast URL

You can get all reactions by a specific cast's target URL by using Airstack Hubs API with the code below:

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

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 reaction data with `getReactionsByTarget`
    const reactionsRes = await client.getReactionsByTarget(
      {
        targetUrl:
          "chain://eip155:1/erc721:0x39d89b649ffa044383333d297e325d42d31329b2",
        reactionType: ReactionType.LIKE,
      },
      metadata,
    );
    console.log(reactionsRes.value);
    // After everything, close the RPC connection
    client.close();
  }
});

Developer Support

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

More Resources

Last updated