Skip to content

Latest commit

 

History

History
305 lines (264 loc) · 7.43 KB

links.md

File metadata and controls

305 lines (264 loc) · 7.43 KB
description
Learn how to fetch Links data using Airstack Hubs API.

🔗 Links

Check If FID Is Following Target FID

You can get check if a given FID is following a target FID by using Airstack Hubs API with the code below:

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

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 link data with `getLink`
    const linkResult = await client.getLink(
      {
        targetFid: 2,
        fid: 6833,
        linkType: "follow",
      },
      metadata
    );
    console.log(linkResult.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/linkById?fid=6833&target_fid=2&link_type=follow`, {
      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" %}

{
  "data": {
    "type": "MESSAGE_TYPE_LINK_ADD",
    "fid": 6833,
    "timestamp": 61144470,
    "network": "FARCASTER_NETWORK_MAINNET",
    "linkBody": {
      "type": "follow",
      "targetFid": 2
    }
  },
  "hash": "0x58c23eaf4f6e597bf3af44303a041afe9732971b",
  "hashScheme": "HASH_SCHEME_BLAKE3",
  "signature": "sMypYEMqSyY...nfCA==",
  "signatureScheme": "SIGNATURE_SCHEME_ED25519",
  "signer": "0x0852c07b56...06e999cdd"
}

{% endtab %} {% endtabs %}

Get Followings By FID

You can get all followings of a given FID by using Airstack Hubs API with the code below:

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

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 link data with `getLinksByFid`
    const linkResult = await client.getLinksByFid(
      {
        fid: 6833,
      },
      metadata
    );
    console.log(linkResult.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/linksByFid?fid=6833`, {
      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" %}

{
  "messages": [
    {
      "data": {
        "type": "MESSAGE_TYPE_LINK_ADD",
        "fid": 6833,
        "timestamp": 61144470,
        "network": "FARCASTER_NETWORK_MAINNET",
        "linkBody": {
          "type": "follow",
          "targetFid": 83
        }
      },
      "hash": "0x094e35891519c0e04791a6ba4d2eb63d17462f02",
      "hashScheme": "HASH_SCHEME_BLAKE3",
      "signature": "qYsfX08mS...McYq6IYMl+ECw==",
      "signatureScheme": "SIGNATURE_SCHEME_ED25519",
      "signer": "0x0852c0...a06e999cdd"
    }
  ],
  "nextPageToken": ""
}

{% endtab %} {% endtabs %}

Get Followers By FID

You can get all followers of a given FID by using Airstack Hubs API with the code below:

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

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 link data with `getLinksByTarget`
    const linkResult = await client.getLinksByTarget(
      {
        targetFid: 6833,
      },
      metadata
    );
    console.log(linkResult.value);
    console.log(reactionsResult.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/linksByTargetFid?target_fid=6833`, {
      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" %}

{
  "messages": [
    {
      "data": {
        "type": "MESSAGE_TYPE_LINK_ADD",
        "fid": 302,
        "timestamp": 61144668,
        "network": "FARCASTER_NETWORK_MAINNET",
        "linkBody": {
          "type": "follow",
          "targetFid": 6833
        }
      },
      "hash": "0x78c62531d96088f640ffe7e62088b49749efe286",
      "hashScheme": "HASH_SCHEME_BLAKE3",
      "signature": "frIZJGIizv...qQd9QJyCg==",
      "signatureScheme": "SIGNATURE_SCHEME_ED25519",
      "signer": "0x59a04...6860ddfab"
    }
  ],
  "nextPageToken": ""
}

{% endtab %} {% endtabs %}

Developer Support

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

More Resources