0

I am trying to read balance from hashpack wallet, for few wallets I created recently it is working fine but for old account created previously not able to read balance and after while maybe after few max attempts getting error

max attempts of 10 was reached for request with last error being: BUSY 

Here is my code

import { AccountBalanceQuery, AccountId, Client, Hbar } from "@hashgraph/sdk"; import { useQuery } from "@tanstack/react-query"; import { BigNumber } from "bignumber.js"; export function useHederaBalance({ accountId, client, wcTopic, hbarxId, }: { accountId: AccountId | null; client: Client | null; wcTopic: string | null; hbarxId: string; }) { return useQuery< { hbar: Hbar; hbarx: BigNumber }, Error, { hbar: Hbar; hbarx: BigNumber }, [ string, string, string, string, { accountId: string | undefined; wcTopic: string | null } ] >({ queryKey: [ "dapp-sdk", "hedera", "hashgraph", "balance", { accountId: accountId?.toString(), wcTopic }, ], queryFn: async () => { if (!accountId || !client) throw new Error("Wallet not connected"); try { const testResult = new AccountBalanceQuery().setAccountId( accountId ); const result = await testResult.execute(client); const hbarxBal = result.tokens?.get(hbarxId)?.toNumber() ?? 0; const hbarxDec = result.tokenDecimals?.get(hbarxId) ?? 1; let hbarx = new BigNumber(hbarxBal.toString()); hbarx = hbarx.div(new BigNumber(10).pow(hbarxDec)); return { hbar: result.hbars, hbarx, }; } catch (error) { console.log("error", error); } return { hbar: new Hbar(0), hbarx: new BigNumber(0), }; }, enabled: !!accountId && !!client && !!wcTopic, staleTime: 5 * 60 * 1000, refetchInterval: 5 * 60 * 1000, }); } 

Versions I am using "@hashgraph/hedera-wallet-connect": "^1.5.1", "@hashgraph/sdk": "^2.62.0",

I am expecting to solution which can fix my issue and read balance

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.