useProfileBalance hook.
Balance Display Configuration
You can customize how balances are displayed and calculated through theparaModalConfig.balances property in your ParaProvider configuration. This setting will impact both the Para Modal’s balance display and instances where you use the useProfileBalance hook.
Para supports two primary balance display modes, AGGREGATED and CUSTOM_ASSET. You can also specify whether to fetch balances for both MAINNET_AND_TESTNET (default) or one or the other only (MAINNET or TESTNET).
Defining Custom Networks and Assets
To include custom assets when fetching connected wallet balances, you will need to supply implementation metadata for each asset, including:- Each asset must include basic metadata, including
name,symbol, andlogoUrl(optional). - Each asset must include an
implementationsarray for each network you wish to query for balances.- Each implementation object must include:
- Price data:
- For a fixed price:
- Include a
priceobject with the asset’s price in the format{ value: number; currency: 'USD' }.
- Include a
- For a volatile price:
- Include a
priceUrlstring. This endpoint must respond to GET requests with a JSON object with the asset’s current price in the format{ value: number; currency: 'USD' }.
- Include a
- For a fixed price:
- Network information:
- For a custom EVM network:
- Include a
networkobject specifying the network’sname,evmChainId, and anrpcUrlwhere asset balances can be queried.- If the network is a testnet, include
isTestnet: true. - Include a
nativeTokenSymbolif the network’s native token is not Ethereum (ETH). - Optional: Include a
logoUrlfor the network. - Optional: Include an
explorerobject for the network, including:- The explorer’s display name
name. - The explorer’s homepage URL
url. - An explorer URL template
txUrlFormatfor broadcast transactions, using{HASH}as the placeholder for the transaction hash. Example:https://etherscan.io/tx/{HASH}
- The explorer’s display name
- If the network is a testnet, include
- If the asset is the network’s native token:
- No additional configuration is needed.
- If the asset is an ERC-20 token:
- Include a
contractAddressstring.
- Include a
- Include a
- For a standard EVM or Solana network:
- Include a
networkstring, matching one of the networks enumerated in theTNetworktype. For example,'ETHEREUM'or'SOLANA'. - Include a
contractAddressstring.
- Include a
- For a custom EVM network:
- Price data:
- Each implementation object must include:
Aggregated Mode (Default)
Aggregated Mode automatically aggregates balances across all detected chains and assets and displays them in USD value. If you supply additional assets and price data, these totals will be included in the calculation. An example configuration with additional assets is below:Balance Overrides
In Aggregated Mode, if you wish, you can manually override the displayed fiat balance for each wallet in the Para Modal. This is useful if you are using a custom chain with many assets that are not included in the calculated total. You can replace the default USD balance for each connected wallet. To do this, you first set theuseBalanceOverrides flag to true in your ParaProvider modal configuration:
ParaProvider, you can calculate and set an override object using the useSetBalanceOverrides hook. Pass an object where the keys are the addresses for your connected wallets (available in the useAccount hook) and the values are numbers representing the USD balance for each wallet.
An example usage:
App.tsx
Custom Asset Mode
In Custom Asset Mode, the Para Modal will only display balances of a chosen asset, with no fiat currency conversion. This is ideal for cases where your app uses a particular token that may not have price information available. Like in Aggregated Mode, you will need to supply implementation metadata for the asset, including any custom network definitions so that its balances can be queried for the session’s connected wallets. However, in this mode, you do not need to include a price object or a price URL.useProfileBalance Hook
TheuseProfileBalance hook allows you to query the current aggregated or custom asset balance of all wallets in the current session.
Balances are normally cached on the server for five minutes. You can supply a refetchTrigger to the hook to manually refetch balances when desired, using a unique number or string.
ProfileBalance object returned by useProfileBalance has the following structure:
- Aggregated
- Custom Asset