Balance and Sync Callbacks
RAILGUN private balances update continuously as new merkle tree commitments are received.
Callback when private balances are updated.
import { setOnBalanceUpdateCallback } from '@railgun-community/wallet';
const onBalanceUpdateCallback = (
chain: Chain,
railgunWalletID: string,
erc20Amounts: {
tokenAddress: string,
amountString: string,
}[],
nftAmounts: {
nftAddress: string,
nftTokenType: NFTTokenType,
tokenSubID: string,
amountString: string,
}[],
): void => {
// Do something with the private token balances.
}
setOnBalanceUpdateCallback(onBalanceUpdateCallback);
The balance and wallet history scans can take a few minutes, so it is recommended to provide a visual indicator of the status to users.
import { MerkletreeScanUpdateEvent } from '@railgun-community/shared-models';
import { setOnMerkletreeScanCallback } from '@railgun-community/wallet';
export const onMerkletreeScanCallback = ({
chain,
scanStatus,
progress,
}: MerkletreeScanUpdateEvent) => {
// Show scan progress in UI with progress bar or loading indicator.
};
setOnMerkletreeScanCallback(onMerkletreeScanCallback);
Last modified 3mo ago