Overview
For complete control over wallet connection flows, you can implement a customWalletProvider that bridges any wallet management solution with Layerswap. This deep integration approach enables you to:
- Use your own custom wallet connection UI
- Integrate 3rd party wallet libraries (Dynamic, Reown, RainbowKit, etc.)
- Control the entire wallet lifecycle (connect, disconnect, state management)
- Customize wallet behavior to match your application’s UX
Creating a Custom Provider
To create a custom provider, use the provider creator function with thecustomHook parameter:
WalletConnectionProvider Interface
Your custom hook must implement this interface:Props Passed to Your Hook
Return Values
| Property | Type | Required | Description |
|---|---|---|---|
connectWallet | () => Promise<Wallet | undefined> | ✅ | Function called when user clicks “Connect Wallet” in the widget |
disconnectWallets | () => Promise<void> | ❌ | Optional function to disconnect all wallets |
activeWallet | Wallet | undefined | ✅ | The currently active/selected wallet |
connectedWallets | Wallet[] | ✅ | Array of all connected wallets |
asSourceSupportedNetworks | string[] | ✅ | Networks supported as swap source |
autofillSupportedNetworks | string[] | ✅ | Networks that support address autofill |
withdrawalSupportedNetworks | string[] | ✅ | Networks that support withdrawals |
name | string | ✅ | Provider name (e.g., “Starknet”, “Ethereum”) |
id | string | ✅ | Unique provider identifier |
providerIcon | string | ❌ | Optional URL to provider icon |
ready | boolean | ✅ | Critical: Whether the provider is initialized and ready to use |
multiStepHandlers | MultiStepHandler[] | ❌ | Optional handlers for multi-step operations |
unsupportedPlatforms | string[] | ❌ | Optional list of unsupported platforms |
hideFromList | boolean | ❌ | Optional flag to hide provider from wallet list |
Wallet Type
Your custom provider must transform external wallet objects to Layerswap’sWallet format:
Complete Example: Dynamic Labs Integration
This example demonstrates integrating Starknet wallets using Dynamic Labs SDK. The same pattern applies to any 3rd party library.Live Demo
Explore the complete source code at layerswap/layerswapapp - nextjs-dynamic example
Installation
Step 1: Create Custom Connection Hook
Create a hook that implements theWalletConnectionProvider interface:
View complete hook implementation (hooks/useCustomStarknet.ts)
View complete hook implementation (hooks/useCustomStarknet.ts)
Step 2: Set Up Providers in Main Component
Step 3: Environment Variables
Create a.env.local file:
Get Your API Keys:
- Dynamic Labs: Sign up at Dynamic
- Layerswap: Generate from the Partner Dashboard
- WalletConnect: Get project ID at WalletConnect Cloud
Critical Implementation Details
Important: These details are critical for correct implementation
-
Icon Resolution: The
iconproperty in theWallettype must return a React component, NOT a URL string. Always use the utility function: -
Ready State: Always return
ready: truein yourWalletConnectionProviderwhen your provider is initialized and ready to handle connections. This is a required field - the widget will not function without it. -
WalletConnect Configs: Only needed for native EVM/SVM/Starknet providers when NOT using a custom hook. If you provide
customHook, the WalletConnect configuration is ignored since you control the connection flow. -
Type Imports: Import types from
@layerswap/widget/types: -
Disconnect Callback: The
disconnectWalletsfunction inWalletConnectionProvideris optional but recommended for proper cleanup. Each individualWalletmust have its owndisconnectcallback.
Implementation Steps
1. Create Custom Hook
ImplementWalletConnectionProvider that:
- Connects to your wallet management solution (Dynamic, Reown, RainbowKit, Privy, etc.)
- Transforms external wallet format to Layerswap
Wallettype - Handles connect/disconnect lifecycle and error states
- Manages wallet state and active wallet selection
- Listens to wallet events (connection, disconnection, account changes)
2. Define Supported Networks
Specify which networks your provider supports:asSource- Networks that can be used as swap sourceautofill- Networks that support address autofillwithdrawal- Networks that support withdrawals
3. Implement Connect Flow
TheconnectWallet function is called when users click “Connect Wallet” in the widget:
4. Handle Wallet State
Keep track of connected wallets and active wallet:5. Create Provider with Custom Hook
Use the factory function with your custom hook:User Experience Flow
Connection Flow
- User opens Layerswap widget
- User clicks “Connect Wallet” button
- Your custom
connectWalletfunction is called - Your custom UI/modal appears (Dynamic, Reown, RainbowKit, etc.)
- User selects wallet and approves connection
- Your hook transforms the wallet to Layerswap format
- Widget displays connected wallet and enables swap functionality
Disconnection Flow
- User clicks disconnect in widget
- Your wallet’s
disconnectcallback is called - Your wallet management library handles cleanup
- Widget updates to show “Connect Wallet” button