Your first API request
Retrieve the configured token list from the public API. Follow the steps to install the SDK, connect to the API, read the response and handle errors.
1. Prepare your environment
This guide uses Node.js 22. Check the version in your terminal and create a new directory. Requests use https://api.hazbase.com by default.
node --version
npm --version
mkdir hazbase-day1
cd hazbase-day1
npm init -y
npm pkg set type=module
npm install --save-exact @hazbase/kit@0.9.0No TypeScript configuration or tsx installation is required. Verify the connection in JavaScript first, then move to TypeScript or React as needed.
2. Run your first request
Save the following as index.mjs and run it. chainId=11155111 selects Sepolia. The response lists tokens configured in this environment; it is not a search across every token on the chain.
import { createHazbaseWalletClient, HazbaseWalletApiError } from "@hazbase/kit/wallet";
// Read-only: no private key, signature, transfer, or transaction is used.
const apiEndpoint = process.env.HAZBASE_API_ENDPOINT || "https://api.hazbase.com";
const chainId = Number(process.env.CHAIN_ID || "11155111");
if (!Number.isSafeInteger(chainId) || chainId <= 0)
throw new Error("CHAIN_ID must be a positive integer.");
const wallet = createHazbaseWalletClient({
apiEndpoint,
fetcher: (url, options) => {
const headers = new Headers(options?.headers);
if (process.env.HAZBASE_API_KEY) headers.set("X-Hazbase-Api-Key", process.env.HAZBASE_API_KEY);
return fetch(url, { ...options, headers, signal: AbortSignal.timeout(15000) });
},
});
try {
const result = await wallet.listTokens({ chainId });
console.log("Connected to:", apiEndpoint);
console.log("Chain ID:", chainId);
console.log("Tokens returned:", result.tokens.length);
console.table(
result.tokens.map(({ name, symbol, standard, decimals, transferable }) => ({
name,
symbol,
standard,
decimals,
transferable,
})),
);
if (result.tokens.length === 0)
console.log("Connection succeeded. No tokens are configured for this chain.");
} catch (error) {
if (error instanceof HazbaseWalletApiError) {
console.error("HTTP status:", error.status, "Code:", error.code ?? "not provided");
}
console.error(error instanceof Error ? error.message : String(error));
process.exitCode = 1;
}
node index.mjs3. Check the result
Success prints “Connected to”, “Chain ID” and “Tokens returned”, followed by a table. Counts and names depend on the environment configuration. Zero tokens still means the API connection succeeded.
{
"tokens": []
}Token entries contain fields including name, symbol, address, standard, decimals and transferable. See the HTTP reference for the complete response type.
GET /api/wallet/tokensCheck the API without an SDK
You can perform the same read with curl. This request does not require an Authorization header or private key.
curl --fail-with-body --max-time 15 \
"https://api.hazbase.com/api/wallet/tokens?chainId=11155111" \
-H "Accept: application/json"Next steps
You have now connected the SDK to the real API. For issuance or transfers, continue with environment configuration, permissions, contracts and wallet setup.