Skip to main content
This guide covers how to implement the wallet aspect of the Dynamic Widget UI Component but using only our SDK hooks and your own UI implementation.

Prerequisites

Like with all this series of headless guides, β€œheadless” is defined a way to use the Dynamic SDK without the need for Dynamic UI components (i.e. DynamicWidget, DynamicUserProfile). You still need to add the SDK and set up the Dynamic Context Provider (complete the quickstart if you haven’t done so already, or refer to an example app)

Signup/Login

Fetch available wallets

You can find the list of available wallets in the walletOptions prop returned by the useWalletOptions hook.
When browsing wallets in the Dynamic Widget, you might see labels beside them like β€œLast Used”, β€œMultichain” or β€œRecommended”.Last used comes from the β€œdynamic_last_used_wallet” value in localstorage. β€œMultichain” comes from the chainGroup node in each wallet (Remember to also add the WalletConnectors for each chain). β€œRecommended” from the Recommended Wallets feature.

Display a wallet icon

Use the @dynamic-labs/wallet-book library to display a wallet icon using the exported WalletIcon component. This component takes a walletKey prop, which is the key of the wallet you want to display.

Connect to a wallet

useWalletOptions allows you to prompt the user to connect using a specific wallet (by passing in the key).

Onramp

Show onramp button and open flow

How: Regular button attached to useOnramp hook Hook/Component: useOnramp Notes: Ensure Banxa is enabled in the Dynamic dashboard

Networks

Display current and available networks

How: Use evmNetworks and getNetwork to fetch, use supportsNetworkSwitching and switchNetwork to switch Hook/Component: useDynamicContext & getNetwork Notes: This example is for Evm networks only

Primary Wallet

Primary wallet is the wallet that is defined as the active one of all your connected wallets. All interactions, such as signing or creating transactions, will be made with this wallet. In addition, when leveraging our multiasset functionality, this is the wallet that will be display all available tokens.

Display primary wallet address

How: Fetch the primary wallet info from context Hook/Component: useDynamicContext Notes: There can be a moment after logging in when it’s not populated yet

Display primary wallet icon

How: Utilize the Walletbook library Hook/Component: WalletIcon (not publicly documented yet) Notes: Requires the primaryWallet.connector object.

Show balance of primary wallet

How: getBalance method from useDynamicContext wallet connector Hook/Component: https://docs.dynamic.xyz/react-sdk/hooks/usedynamiccontext Notes: None

Show all tokens and balances

How: Mapping return from usetokenbalances hook Hook/Component: https://docs.dynamic.xyz/react-sdk/hooks/usetokenbalances Notes: Multi-asset is only supported on the following networks - Ethereum, Optimism, Polygon, Arbitrum, and Base.

Detect Wallet Locking

The wallet object has a field called connected which indicates whether the wallet is locked or not, and you can use this to trigger your own workflow to warn the user.

Multi-Wallet

Show all linked wallets and allow unlinking

How: Mapping return from useUserWallets hook and handleUnlinkWallet from useDynamicContext Hook/Component: https://docs.dynamic.xyz/react-sdk/hooks/useuserwallets & https://docs.dynamic.xyz/react-sdk/hooks/usedynamiccontext Notes: Doesn’t yet show if a wallet is the primary wallet. Unlinking is also handled here.

Detect which wallet is primary

How: You can grab it directly from useDynamicContext Hook/Component: useDynamicContext
How: Pop up our linking modal using a hook (setShowLinkNewWalletModal) Hook/Component: useDynamicModals Notes:
  • You will need to also use the DynamicMultiWalletPromptsWidget component

Switch the primary wallet to another

How: useSwitchWallets hooks Hook/Component: https://docs.dynamic.xyz/react-sdk/hooks/useswitchwallet#useswitchwallet Notes: None

Wallet Interactions

To learn how to send balance, sign messages etc., please check out the Wallet Interaction guides where we split into Read actions and Write actions, and we provide per chain examples for common functionality.