description |
---|
Learn how to fetch username proofs data using Airstack Hubs API. |
You can get username by a specific username by using Airstack Hubs API with the code below:
{% tabs %} {% tab title="@farcaster/hub-nodejs" %}
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 uers name proofs data with `getUserNameProof`
const userNameProofsRes = await client.getUserNameProof(
{ name: new TextEncoder().encode("adityapk") },
metadata
);
console.log(userNameProofsRes.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/userNameProofByName?name=adityapk`, {
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" %}
{
"timestamp": 1670603245,
"name": "adityapk",
"owner": "Oi7uUaECifDm+larm+rzl3qQhcM=",
"signature": "fo5OhBP/ud...3IoJdhs=",
"fid": 6833,
"type": "USERNAME_TYPE_FNAME"
}
{% endtab %} {% endtabs %}
You can get username by a specific FID by using Airstack Hubs API with the code below:
{% tabs %} {% 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/userNameProofsByFid?fid=2`, {
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="@farcaster/hub-nodejs" %}
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 uers name proofs data with `getUserNameProofsByFid`
const userNameProofsRes = await client.getUserNameProofsByFid(
{ fid: 2 },
metadata
);
console.log(verificationRes.value);
// After everything, close the RPC connection
client.close();
}
});
{% endtab %}
{% tab title="Response" %}
{
"proofs": [
{
"timestamp": 1623910393,
"name": "v",
"owner": "0x4114e33eb831858649ea3702e1c9a2db3f626446",
"signature": "bANBae+Ub...kr3Bik4xs=",
"fid": 2,
"type": "USERNAME_TYPE_FNAME"
},
{
"timestamp": 1690329118,
"name": "varunsrin.eth",
"owner": "0x182327170fc284caaa5b1bc3e3878233f529d741",
"signature": "zCEszPt...zqxTiFqVBs=",
"fid": 2,
"type": "USERNAME_TYPE_ENS_L1"
}
]
}
{% endtab %} {% endtabs %}
If you have any questions or need help regarding integrating username proofs data using AIrstack Hubs API into your Farcaster app, please join our Airstack's Telegram group.