Balance and Sync Callbacks

RAILGUN private balances update continuously as new merkle tree commitments are received.
This process involves two callback events, which you should set after Engine initialization.

Balance update callback

Callback when private balances are updated.

Example: Set callback for balance updates

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);

Scan progress callback

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.

Example: Set callback for scan events

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);