TokenBalancesListView
, this is what we’ll be using within this example. TokenBalancesListView
retrieves and displays the tokens (both native and ERC20) that an address owns across a given list of networks.NFTWalletTokensListView
, similar to the previous component, NFTWalletTokensListView
displays a list of NFTs owned by an address (including information such as the estimated value of each NFT, the images, collection names, etc.)NFTCollectionTokenListView
, for displaying high-level information about all NFTs present within a specified collection.NFTDetailView
, to show rich information about a single NFT, including its attributes, sale and floor price history, etc.TokenTransfersListView
, for viewing an explorer-like list of token transfers (one token at a time) executed by a users wallet address.TokenBalancesListView
to provide insights into the users token balances on a few different networks.
An example of this configuration with a few placeholders alongside the interface it’ll directly produce has been included below.
TokenBalancesListView
will need to be wrapped by an additional component to pass in the API key and optional high-level customizations (similar to AuthCoreContextProvider
or ModalProvider
within Particle’s various SDKs), such as is shown here:
TokenBalancesListView
.@particle-network/connectkit
) and GoldRush (@covalenthq/goldrush-kit
). To install these SDKs (alongside two additional libraries for configuring Particle Connect), run one of the two following commands at the root of your project (ideally, this should either be using Next.js or a standard create-react-app structure; we’ll be using the latter).
ModalProvider
within the index
file (or the equivalent within your application), and as mentioned for GoldRush, this will be done through GoldRushProvider
, both following a similar configuration structure. To start, you’ll need to retrieve four API keys; three from the Particle dashboard and one from the Covalent dashboard. Specifically, you’ll need:
projectId
, clientKey
, and appId
from the Particle dashboard. These will be used to configure ModalProvider
from @particle-network/connectkit
; the collection of these values simultaneously authenticate API requests and allow you to track connected wallets, customize the Particle Auth modal, etc.apikey
from the Covalent dashboard. apikey
will be used to authenticate API requests made within the TokenBalancesListView
React component to retrieve token balances.ModalProvider
will be configured through wrapping the primary application component in which you intend to use Particle Connect (in this example, it’s App
, although alternatively, ModalProvider
can be used directly within the component rather than within index
). ModalProvider
takes various parameters, including:
projectId
, clientKey
, and appId
. As covered, these will be used to authenticate and connect your project to the Particle dashboard.chains
, the chains you intend to support within Particle Connect. This parameter isn’t relevant for this example given the read-only nature of the interface we’re setting up, thus this can simply be set to Ethereum
from @particle-network/chains
.connectors
, an array of wallet connectors representing the specific wallets you’d like to be supported by the connection modal. @particle-network/connectors
has an export, evmWallets
, which contains a variety of supported EVM wallets (such as MetaMask, WalletConnect, Trust, etc.); we’ll be using this within connectors. evmWallets
takes the following parameters:
projectId
, your WalletConnect project ID retrieved from the WalletConnect dashboard.showQrModal
to enable connection via QR codes with the QR modal.wallet
, an optional parameter to dictate whether or not the embedded wallet interface is shown; if it is, you can use wallet
to customize the style, lock chain selection, etc. Although in this case, we’ll pass the following parameter:
visible
, which will be false
in this case, as we’ll be relying on the component from GoldRush to view balances, rather than using the embedded wallet (although that’s not to say both wouldn’t work; for the sake of this example we’ll allow the GoldRush component to be the exclusive interface for asset information).index
file, or wherever you’re wrapping your application component(s) with ModalProvider
, should look like the following example.
ModalProvider
has been configured and therefore Particle Connect is ready to be used, we’ll need to build out our application component (this was App
referenced within the previous code snippet). This will be quite simple and primarily involve:
ConnectButton
if the user hasn’t already connected. To do this, we’ll be pulling the active wallet address with the useAccount
hook, imported from @particle-network/connectkit
.account
from useAccount
is populated), we’ll shift to a page containing TokenBalancesListView
, passing in address
(the address from which balances will be reflected) as account
.TokenBalancesListView
will be wrapped within GoldRushProvider
, using the API key retrieved prior to authenticate the (built-in) Covalent API.ConnectButton
component (facilitating wallet connection). As mentioned, we’ll only be using one hook for this example, useAccount
. This’ll automatically update the variable assigned to it with a wallet address after a user has connected through ConnectButton
, allowing us to use it as an anchor for deciding whether or not a user has already logged in (and thus determining which page to display). An example of initializing an address variable attached to useAccount
has been included below.
useAccount
will be the only line within this component, everything else will be formatted within its JSX. Moving on, we’ll need to conditionally display the “Connect Wallet” button based upon the truthy/falsy value of account
. If account
is undefined, indicating a user has yet to connect their wallet, the ConnectButton
component will be shown (through <ConnectButton />
).
Otherwise, if account
is defined, GoldRushProvider
and TokenBalancesListView
can be shown. GoldRushProvider
, in this example, will take one parameter:
apikey
, the Covalent API key previously retrieved from the Covalent dashboard.theme
, mode
, border_radius
, and color
for high-level, global customizations (affecting all GoldRush components wrapped by GoldRushProvider
).GoldRushProvider
should be TokenBalancesListView
, which contains:
chain_names
, the list of chains to be included in the list of token balances (they’ll be queried collectivelly, each contributing to the list of balances). The full list of supported chains can be found on the Covalent documentation.address
, the targeted address (one at a time). We’ll be using account
(from useAccount
) for this.mask_balances
and hide_small_balances
can be included, alongside the on_transfer_click
function (which will handle the “View Transfer History” button attached to each token; this should be linked to the TokenTransfersListView
component if you’re planning on using it).ConnectButton
), users will now be presented with a detailed, in-app view of their token balances across every chain listed within chain_names
(on TokenBalancesListView
). Although GoldRush aims to provide a cohesive suite of components, meaning TokenTransfersListView
, NFTDetailView
, NFTWalletTokensListView
, etc. will fit in as easily as was shown above with TokenBalancesListView
, enabling a simple, data-rich alternative for displaying wallet information with Particle Connect in under 50 lines of code.