Skip to main content

Recommended: JavaScript SDK with React Hooks

For new React apps, we recommend the JavaScript SDK with React Hooks (@dynamic-labs-sdk/react-hooks) instead of the legacy React SDK documented here. The JS SDK comes with many benefits such as a much smaller bundle size and other optimizations. Use the React quickstart (JavaScript SDK) to get started.

Overview

This guide shows you how to build a custom multi-chain bridging interface from scratch using Dynamic SDK hooks. You’ll learn how to:
  • Connect a source wallet on one chain (e.g., EVM, Solana, Bitcoin, Sui)
  • Connect a destination wallet on another chain
  • Select and switch between different chains
  • Manage multiple wallet connections simultaneously
  • Access wallet instances to perform bridge transactions

Setup

Configure your DynamicContextProvider with the required wallet connectors for all chains you want to support:
providers.tsx
This setup configures the Dynamic SDK with all the wallet connectors needed for multi-chain bridging. Each connector enables support for its respective blockchain ecosystem, allowing users to connect wallets from different chains simultaneously.

Core Hooks

Use these Dynamic SDK hooks:
  • useDynamicContext - SDK state and wallet management (sdkHasLoaded, removeWallet, primaryWallet)
  • useUserWallets - Get all connected wallets
  • useSwitchWallet - Switch the primary wallet
  • useWalletOptions - Get available wallets and connect (selectWalletOption, getFilteredWalletOptions)
  • FilterChain - Filter wallets by chain type
  • ChainEnum - Chain type constants

Chain Constants

First, create a constants file to define chain display names and supported chains:
consts.ts

Chain Selector Component

Create a chain selector component to allow users to choose source and destination chains:
ChainSelector.tsx
The ChainSelector component provides a dropdown interface for selecting chains. It displays chain names from a predefined list and can be configured to filter available options, making it reusable for both source and destination chain selection. To customize which chains appear, update the CHAIN_DISPLAY_NAMES and SUPPORTED_CHAINS constants in src/lib/consts.ts.

Wallet Modal Component

Create a modal component for connecting wallets:
WalletModal.tsx
The WalletModal component displays available wallets for a specific chain when opened. It filters wallets by chain type using FilterChain, sorts them to show installed wallets first, and handles wallet connection via selectWalletOption. The modal closes automatically after a wallet is selected.

Complete Implementation

Here’s the complete bridge component that matches the real implementation:
HeadlessBridgeWidget.tsx
This is the main bridge widget component that orchestrates multi-chain wallet management. The component tracks source and destination chains, connected wallets, and modal state. It separates wallets by chain type for source and destination, ensuring the source wallet is always the primary wallet (for transaction signing), while destination wallets can be any connected wallet. The component prevents selecting the same chain for both source and destination, and conditionally renders either a connect button, a simple wallet display, or a dropdown menu based on wallet connection state and count. It automatically makes the source wallet primary when it changes via a useEffect hook. The component uses memoization (useMemo) for performance optimization and callbacks (useCallback) to prevent unnecessary re-renders.

Key Concepts

Primary Wallet vs Destination Wallet

  • Source Wallet: Should be the primary wallet (use switchWallet to set it). The source wallet is automatically set as primary when connected.
  • Destination Wallet: Can be any connected wallet (track with selectedDestinationWalletId). The destination wallet doesn’t need to be primary.

Chain Selection

The component prevents selecting the same chain for both source and destination:
This filtering logic ensures users can’t select the same chain for both source and destination. The useMemo hook recalculates available chains only when the destination chain changes, preventing invalid bridge configurations.

Wallet Filtering

Filter wallets by chain using FilterChain:
FilterChain is a utility function that creates a filter predicate for wallet options. When passed to getFilteredWalletOptions, it returns only wallets compatible with the specified chain type, making it easy to show chain-specific wallet options in your UI.

Connecting Wallets

Use selectWalletOption to connect a new wallet:
selectWalletOption connects a new wallet to the user’s account. The second parameter (createLinkedAccount: true) creates a linked account if needed, and the third parameter (setAsPrimary: true) makes the newly connected wallet the primary wallet, which is important for the source wallet in bridge transactions.

Accessing Wallet Instances

EVM Wallet

Solana Wallet

Bitcoin Wallet

Sui Wallet

You can check out detailed information on interacting with different chains in the Wallets section.

Next Steps: Integrating Bridge Providers

Now that you have a custom multi-chain bridging UI set up, you can integrate with bridge providers to enable actual token transfers between chains. Check out our integration guides: These guides will show you how to use the wallet instances from your bridge widget to execute bridge transactions with various providers.

See Also

Last modified on June 25, 2026