âī¸Onchain Events
Learn how to fetch Hub events data using Airstack Hubs API.
Get Onchain Events By FID
You can get all Farcaster onchain events by a specific FID by using Airstack Hubs API with the code below:
import {
Metadata,
getSSLHubRpcClient,
OnChainEventType,
} 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 onchain event data with `getOnChainEvents`
const eventRes = await client.getOnChainEvents(
{
fid: 3,
eventType: OnChainEventType.EVENT_TYPE_SIGNER,
},
metadata
);
console.log(eventRes.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/onChainEventsByFid?fid=3&event_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();
{
"events": [
{
"type": "EVENT_TYPE_SIGNER",
"chainId": 10,
"blockNumber": 108875456,
"blockHash": "0x75fbbb8b2a4ede67ac350e1b0503c6a152c0091bd8e3ef4a6927d58e088eae28",
"blockTimestamp": 1693349689,
"transactionHash": "0x36ef79e6c460e6ae251908be13116ff0065960adb1ae032b4cc65a8352f28952",
"logIndex": 2,
"fid": 3,
"signerEventBody": {
"key": "0xc887f5bf385a4718eaee166481f1832198938cf33e98a82dc81a0b4b81ffe33d",
"keyType": 1,
"eventType": "SIGNER_EVENT_TYPE_ADD",
"metadata": "AAAAAAAAA...AAAAA",
"metadataType": 1
},
"txIndex": 0
}
]
}
Get Onchain Signers By FID
You can get all signers by a specific FID 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 onchain event data with `getOnChainSignersByFid`
const eventRes = await client.getOnChainSignersByFid(
{
fid: 6833,
},
metadata
);
console.log(eventRes.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/onChainSignersByFid?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();
{
"events": [
{
"type": "EVENT_TYPE_SIGNER",
"chainId": 10,
"blockNumber": 108875854,
"blockHash": "0xceb1cdc21ee319b06f0455f1cedc0cd4669b471d283a5b2550b65aba0e0c1af0",
"blockTimestamp": 1693350485,
"transactionHash": "0x76e20cf2f7c3db4b78f00f6bb9a7b78b0acfb1eca4348c1f4b5819da66eb2bee",
"logIndex": 2,
"fid": 6833,
"signerEventBody": {
"key": "0x0852c07b5695ff94138b025e3f9b4788e06133f04e254f0ea0eb85a06e999cdd",
"keyType": 1,
"eventType": "SIGNER_EVENT_TYPE_ADD",
"metadata": "AAAAAAAAAAAA...AAAAAAAA",
"metadataType": 1
},
"txIndex": 0
}
]
}
Get Onchain Id Registry Event By Address
You can get all onchain events for a given address 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);
const addressHex = "0xbfe1716f8d0fd949ca399a8a8a98b80d17e44372";
const addressBytes = hexStringToBytes(addressHex)._unsafeUnwrap();
// Fetch onchain event data with `getOnChainSignersByFid`
const eventRes = await client.getIdRegistryOnChainEventByAddress(
{
address: addressBytes,
},
metadata
);
console.log(eventRes.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/onChainIdRegistryEventByAddress?address=0x74232bf61e994655592747e20bdf6fa9b9476f79`, {
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();
{
"type": "EVENT_TYPE_ID_REGISTER",
"chainId": 10,
"blockNumber": 108874508,
"blockHash": "0x20d83804a26247ad8c26d672f2212b28268d145b8c1cefaa4126f7768f46682e",
"blockTimestamp": 1693347793,
"transactionHash": "0xf3481fc32227fbd982b5f30a87be32a2de1fc5736293cae7c3f169da48c3e764",
"logIndex": 7,
"fid": 3,
"idRegisterEventBody": {
"to": "0x74232bf61e994655592747e20bdf6fa9b9476f79",
"eventType": "ID_REGISTER_EVENT_TYPE_REGISTER",
"from": "0x",
"recoveryAddress": "0x00000000fcd5a8e45785c8a4b9a718c9348e4f18"
},
"txIndex": 0
}
Developer Support
If you have any questions or need help regarding integrating Farcaster onchain events data using AIrstack Hubs API into your Farcaster app, please join our Airstack's Telegram group.
More Resources
Last updated