Learn how to use Airstack by making direct API call without Airstack SDK. In this tutorial, you will learn how to integrate in Node.js. However, this should also work in any other tech stacks.
đ¯ Direct API Call
In this tutorial, you will learn how to start integrating Airstack API by making direct API call without the Airstack SDKs.
While this method is most useful when you already have an app that is using languages not supported by the Airstack SDKs, such as JavaScript/TypeScript and Python, this get starting guide will be using Node.js as an example.
All the concepts here for integrating Airstack GraphQL API should be translatable to any tech stacks you are using.
GraphQL API Library
You can call the Airstack API by using a 3rd party GraphQL API library with the following details:
If you are using Node version 20.6.0+, then you can simply import the environment variable to you Node.js app. Thus, directly proceed to the next step.
If you are using Node version earlier than 20.6.0, then you need to install the dotenv package:
npm install dotenv
yarn add dotenv
pnpm install dotenv
and import the package to be able to inject the environment variable to your application:
index.ts
import { config } from "dotenv";
config();
index.js
import { config } from "dotenv";
config();
Step 3: Call Your Query
Once you have installed one of the 3rd party SDK, you can directly make calls to the Airstack API.
Below you have been provided with Airstack query to fetch the 0x address and Farcaster owned by vitalik.eth:
import { gql, GraphQLClient } from "graphql-request";
interface Data {
Wallet: Wallet;
}
interface Error {
message: string;
}
interface Wallet {
socials: Social[];
addresses: string[];
}
interface Social {
dappName: "farcaster";
profileName: string;
}
const AIRSTACK_API_URL = "https://api.airstack.xyz/graphql";
const AIRSTACK_API_KEY = process.env.AIRSTACK_API_KEY;
const query = gql`
query MyQuery {
Wallet(input: { identity: "vitalik.eth", blockchain: ethereum }) {
socials {
dappName
profileName
}
addresses
}
}
`;
if (!AIRSTACK_API_KEY) throw new Error("AIRSTACK_API_KEY not set");
const graphQLClient = new GraphQLClient(AIRSTACK_API_URL, {
headers: {
Authorization: AIRSTACK_API_KEY, // Add API key to Authorization header
},
});
const main = async () => {
try {
const data = await graphQLClient.request<Data>(query);
console.log(data);
} catch (e) {
throw new Error((e as Error)?.message)
}
}
main();
import { gql, GraphQLClient } from "graphql-request";
const AIRSTACK_API_URL = "https://api.airstack.xyz/graphql";
const AIRSTACK_API_KEY = process.env.AIRSTACK_API_KEY;
const query = gql`
query MyQuery {
Wallet(input: { identity: "vitalik.eth", blockchain: ethereum }) {
socials {
dappName
profileName
}
addresses
}
}
`;
if (!AIRSTACK_API_KEY) throw new Error("AIRSTACK_API_KEY not set");
const graphQLClient = new GraphQLClient(AIRSTACK_API_URL, {
headers: {
Authorization: AIRSTACK_API_KEY, // Add API key to Authorization header
},
});
const main = async () => {
try {
const data = await graphQLClient.request(query);
console.log(data);
} catch (e) {
throw new Error(e?.message)
}
}
main();
index.ts
import fetch from "node-fetch";
interface QueryResponse {
data: Data;
}
interface Data {
Wallet: Wallet;
}
interface Error {
message: string;
}
interface Wallet {
socials: Social[];
addresses: string[];
}
interface Social {
dappName: "lens" | "farcaster";
profileName: string;
}
const AIRSTACK_API_URL = "https://api.airstack.xyz/graphql";
const AIRSTACK_API_KEY = process.env.AIRSTACK_API_KEY;
const query = `
query MyQuery {
Wallet(input: {identity: "vitalik.eth", blockchain: ethereum}) {
socials {
dappName
profileName
}
addresses
}
}
`;
const main = async () => {
try {
if (!AIRSTACK_API_KEY) throw new Error("AIRSTACK_API_KEY not set");
const res = await fetch(AIRSTACK_API_URL, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: AIRSTACK_API_KEY, // Add API key to Authorization header
},
body: JSON.stringify({ query }),
});
const json = (await res?.json()) as QueryResponse;
const data = json?.data;
console.log(data);
} catch (e) {
throw new Error((e as Error)?.message);
}
};
main();
index.js
import fetch from "node-fetch";
const AIRSTACK_API_URL = "https://api.airstack.xyz/graphql";
const AIRSTACK_API_KEY = process.env.AIRSTACK_API_KEY;
const query = `
query MyQuery {
Wallet(input: {identity: "vitalik.eth", blockchain: ethereum}) {
socials {
dappName
profileName
}
addresses
}
}
`;
const main = async () => {
try {
if (!AIRSTACK_API_KEY) throw new Error("AIRSTACK_API_KEY not set");
const res = await fetch(
AIRSTACK_API_URL,
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: AIRSTACK_API_KEY // Add API key to Authorization header
},
body: JSON.stringify({ query }),
}
);
const json = await res?.json();
const data = json?.data;
console.log(data);
} catch (e) {
throw new Error(e?.message);
}
}
main();
The data variable will return and logged into your terminal as follows:
If you have any questions or need help regarding integrating Airstack using direct API call into your web3 application, please join our Airstack's Telegram group.
More Resources
Learn to build more with Airstack using our tutorials: