Skip to main content

Usage

const {
  data,
  isLoading,
  isError,
  isSuccess,
  error,
  refetch,
  fetchTokenBalance,
} = useGetTokenBalance({
  params: {
    chainToken: "USDC",
    chain: "STARKNET",
    walletPublicKey: "0x...",
  },
  getBearerToken: getToken,
});

Input Parameters

ParameterTypeRequiredDescription
params.chainTokenChainTokenYesToken identifier (e.g. "USDC")
params.chainstringYesBlockchain network (e.g. "STARKNET")
params.walletPublicKeystringNoWallet address to check balance for
params.externalUserIdstringNoExternal user ID (alternative to walletPublicKey)
getBearerToken() => Promise<string>YesFunction returning the auth token
queryOptionsUseQueryOptionsNoReact Query options (e.g. staleTime, enabled)

Return Value

PropertyTypeDescription
dataGetTokenBalanceResponse | undefinedBalance data
isLoadingbooleanTrue while fetching
isErrorbooleanTrue if an error occurred
isSuccessbooleanTrue if the query succeeded
errorError | nullError when isError is true
refetch() => voidRe-run the query
fetchTokenBalance(input) => Promise<GetTokenBalanceResponse>Imperatively fetch balance with custom params

Example Implementation

import { useGetTokenBalance } from "@chipi-stack/chipi-react";
import { useAuth } from "@clerk/nextjs";

export function TokenBalance({ walletPublicKey }: { walletPublicKey: string }) {
  const { getToken } = useAuth();

  const { data, isLoading, error } = useGetTokenBalance({
    params: {
      chainToken: "USDC",
      chain: "STARKNET",
      walletPublicKey,
    },
    getBearerToken: getToken,
  });

  if (isLoading) return <p>Loading balance...</p>;
  if (error) return <p>Error: {error.message}</p>;

  return (
    <div>
      <p>Balance: {data?.balance} USDC</p>
    </div>
  );
}
Either walletPublicKey or externalUserId must be provided to identify the wallet.