đ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();
}
});
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/reactionById?fid=428529&reaction_type=1&target_fid=439224&target_hash=0xbf35c9dc91bf964c7da3fc1fe2a6925e2db472c5`, {
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();
{
"data": {
"type": "MESSAGE_TYPE_REACTION_ADD",
"fid": 2,
"timestamp": 72752656,
"network": "FARCASTER_NETWORK_MAINNET",
"reactionBody": {
"type": "REACTION_TYPE_LIKE",
"targetCastId": {
"fid": 1795,
"hash": "0x7363f449bfb0e7f01c5a1cc0054768ed5146abc0"
}
}
},
"hash": "0x9fc9c51f6ea3acb84184efa88ba4f02e7d161766",
"hashScheme": "HASH_SCHEME_BLAKE3",
"signature": "F2OzKsn6Wj...gtyORbyCQ==",
"signatureScheme": "SIGNATURE_SCHEME_ED25519",
"signer": "0x78ff9a7...647b6d62558c"
}
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();
}
});
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/reactionsByFid?fid=2&reaction_type=1`, {
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();
{
"messages": [
{
"data": {
"type": "MESSAGE_TYPE_REACTION_ADD",
"fid": 2,
"timestamp": 72752656,
"network": "FARCASTER_NETWORK_MAINNET",
"reactionBody": {
"type": "REACTION_TYPE_LIKE",
"targetCastId": {
"fid": 1795,
"hash": "0x7363f449bfb0e7f01c5a1cc0054768ed5146abc0"
}
}
},
"hash": "0x9fc9c51f6ea3acb84184efa88ba4f02e7d161766",
"hashScheme": "HASH_SCHEME_BLAKE3",
"signature": "F2OzKsn6WjP8MTw...hqUbrAvp6mggtyORbyCQ==",
"signatureScheme": "SIGNATURE_SCHEME_ED25519",
"signer": "0x78ff9a768...62558c"
}
],
"nextPageToken": ""
}
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();
}
});
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/reactionsByCast?target_fid=439224&reaction_type=1&target_hash=0xbf35c9dc91bf964c7da3fc1fe2a6925e2db472c5`, {
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();
{
"messages": [
{
"data": {
"type": "MESSAGE_TYPE_REACTION_ADD",
"fid": 426,
"timestamp": 72750141,
"network": "FARCASTER_NETWORK_MAINNET",
"reactionBody": {
"type": "REACTION_TYPE_LIKE",
"targetCastId": {
"fid": 1795,
"hash": "0x7363f449bfb0e7f01c5a1cc0054768ed5146abc0"
}
}
},
"hash": "0x7662fba1be3166fc75acc0914a7b0e53468d5e7a",
"hashScheme": "HASH_SCHEME_BLAKE3",
"signature": "tmAUEYlt/+...R7IO3CA==",
"signatureScheme": "SIGNATURE_SCHEME_ED25519",
"signer": "0x13dd2...204e57bc2a"
}
],
"nextPageToken": ""
}
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();
}
});
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/reactionsByTarget?url=chain://eip155:1/erc721:0x39d89b649ffa044383333d297e325d42d31329b2`, {
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();
{
"messages": [
{
"data": {
"type": "MESSAGE_TYPE_REACTION_ADD",
"fid": 1134,
"timestamp": 79752856,
"network": "FARCASTER_NETWORK_MAINNET",
"reactionBody": {
"type": "REACTION_TYPE_LIKE",
"targetUrl": "chain://eip155:1/erc721:0x39d89b649ffa044383333d297e325d42d31329b2"
}
},
"hash": "0x94a0309cf11a07b95ace71c62837a8e61f17adfd",
"hashScheme": "HASH_SCHEME_BLAKE3",
"signature": "+f/+M...0Uqzd0Ag==",
"signatureScheme": "SIGNATURE_SCHEME_ED25519",
"signer": "0xf6...3769198d4c"
}
],
"nextPageToken": ""
}
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