Why Your Wallet Balance Is Lying: Keeping Web3 UIs Fresh After a Transaction
Reading time: 4 minutesA user approves a transfer in an institutional dashboard. Their wallet confirms it. The success toast appears. And the balance on screen has not moved.
They refresh the page, and now it is right. Nothing was broken on-chain; the UI was just showing data from before the transaction. But to the user, especially someone moving real assets on behalf of an institution, a balance that lags behind reality looks like a bug, or worse, like money went missing.
This is a very common problem in Web3 frontends, and there is no single fix. Here is how I approached it, piece by piece.
Why it happens
Three things combine:
- Caching. The dashboard caches balances and transaction lists so pages load fast. That cache does not know a transaction just happened.
- “Sent” is not “done”. When the wallet returns a transaction hash, the transaction has been submitted, not included in a block. Refetching at that moment returns the old state, correctly.
- Indexers lag. Transaction history often comes from an indexer, not directly from the chain. Even after the block is final, the indexer may be a few blocks behind.
So the honest answer to “why is the balance wrong?” is that the UI asked too early, asked the wrong source, or never asked at all.
Wait for the receipt, not the hash
The first rule: refresh when the transaction is included, not when it is submitted.
const hash = await walletClient.writeContract(request);
markPending({ hash, network, wallet, token }); // show "pending" right away
const receipt = await publicClient.waitForTransactionReceipt({ hash });
if (receipt.status === "success") {
await refreshAfterTx({ network, wallet, token, blockNumber: receipt.blockNumber });
} else {
markFailed(hash);
}
The receipt also tells you whether the transaction actually succeeded. A reverted transaction still has a receipt, and treating it as success is a quiet way to show users something that never happened.
Refresh only what changed
My first instinct was to invalidate everything after a transaction. It works, but on a dashboard with many wallets, tokens and networks, it means a burst of requests and a page that reloads half of itself for one transfer.
Instead, the refresh is targeted. A transaction touches a known set of things: a network, a wallet, one or more tokens. So the cache is keyed the same way, and only those keys are refreshed:
type BalanceKey = `${NetworkId}:${Address}:${TokenId}`;
async function refreshAfterTx({ network, wallet, token, blockNumber }: TxContext) {
await Promise.all([
balances.refresh(`${network}:${wallet}:${token}`),
transactions.refresh({ network, wallet, minBlock: blockNumber }),
]);
}
Other wallets, other networks and other tokens keep their cached values. The page does exactly as much work as the transaction justifies.
Show the change optimistically, then confirm it
Waiting for a receipt can take seconds. During that time, the user should still see what they just did.
For simple cases, like sending a known amount of a token, the store applies the expected change immediately and marks it as pending:
balances.applyOptimistic(key, { delta: -amount, txHash: hash });
// UI: 9,500 USDC (pending) instead of 10,000 USDC
When the receipt arrives, the real balance is fetched from the chain and replaces the optimistic value. If the two disagree, because of fees, rounding, a partial fill or a transfer from somewhere else, the chain wins, always. If the transaction fails, the optimistic change is rolled back.
The rule I hold to: optimistic values are a preview, never a source of truth. They are always labelled as pending, and they are always reconciled against the chain.
Don’t flicker
The naive refresh clears the old balance, shows a spinner, then shows the new balance. On a dashboard, that flash of empty state is worse than a slightly stale number, because for a moment it looks like the user has nothing.
So refreshes keep the previous value on screen and mark it as updating:
// Before: data cleared → spinner → new data (flicker)
// After: old data stays visible with a subtle "updating" state → swapped when ready
set((s) => ({ entries: { ...s.entries, [key]: { ...s.entries[key], stale: true } } }));
const fresh = await fetchBalance(key);
set((s) => ({ entries: { ...s.entries, [key]: { value: fresh, stale: false } } }));
The user always sees a number. It just updates in place.
Mind the indexer
Balances can be read directly from the chain, but transaction lists usually come from an indexer. If you refetch the history the moment the receipt lands, the indexer may not have processed that block yet, and the new transaction is missing.
The fix is to refetch history until the indexer has caught up to the transaction’s block:
async function refreshHistory({ network, wallet, minBlock }: HistoryRefresh) {
for (let attempt = 0; attempt < 10; attempt++) {
const { items, indexedBlock } = await indexer.history(network, wallet);
if (indexedBlock >= minBlock) return setHistory(network, wallet, items);
await sleep(1_000 * (attempt + 1)); // back off while the indexer catches up
}
showNotice("History is catching up; your transaction is confirmed on-chain.");
}
Most indexers expose the latest block they have processed. Comparing it with the receipt’s block number turns “maybe it’s there” into a clear condition.
Don’t forget approvals and orders
The balance was the obvious stale value. Less obvious ones caused more confusion:
- Allowances. After an
approveor a Permit2 signature, the flow has to re-read the allowance. Otherwise the UI asks the user to approve again, for something they just approved. - Orders and pending actions. After signing an order or a multisig proposal, the list of open orders or pending proposals has to refresh, or the user signs the same thing twice.
So every signing flow ends with an explicit “what did this change?” step that refreshes those specific queries, not just balances.
What changed for users
After these changes, the dashboard behaves the way people expect from a banking app: you act, you immediately see the effect marked as pending, and within moments it is confirmed against the chain, without the page reloading or flashing empty.
The broader lesson is that “fresh data” in Web3 is not one problem. It is four: when to ask (after the receipt), what to ask for (only what changed), what to show meanwhile (an honest pending state, never a blank), and which source to trust (the chain over the cache, and the chain over the indexer until it catches up).