Overview
For applications that already use wagmi for EVM wallet management, Layerswap offers seamless integration that detects and manages externally connected wallets. This hybrid approach gives you the best of both worlds: your existing wallet infrastructure plus Layerswap’s swap functionality.How It Works
When you integrate Layerswap with your existing wagmi configuration:- External Connection Detection - Wallets connected outside the widget (through your app’s UI) are automatically detected and displayed in Layerswap
- Bidirectional Management - Users can connect and disconnect wallets from both your app’s UI and the Layerswap widget
- Unified State - Single source of truth for wallet connections across your entire application
Implementation
Prerequisites
Your application should already have:wagmiinstalled and configured@tanstack/react-queryset up- Wallet connectors configured (WalletConnect, MetaMask, Coinbase, etc.)
Step 1: Install Layerswap Packages
Step 2: Fetch Layerswap Settings
Use theuseSettings hook to fetch Layerswap’s network configurations:
Server-Side Settings: For server-side rendering (SSR), you can fetch Layerswap settings server-side using the This allows you to pre-configure Layerswap networks on the server before rendering, eliminating the loading state on the client.
getSettings() function:Step 3: Configure Wagmi with Layerswap Networks
UseuseChainConfigs to get chain configurations from Layerswap settings:
Complete Example
Here’s a full example showing the entire integration:User Experience Flow
Scenario 1: User Connects via Your App
- User clicks “Connect Wallet” in your app’s header
- User selects MetaMask and approves connection
- Your app displays connected wallet in header
- Layerswap widget automatically detects the wallet and shows it as connected
- User can now use Layerswap swap features immediately
Scenario 2: User Connects via Layerswap Widget
- User opens Layerswap widget (no wallet connected yet)
- User clicks “Connect Wallet” in the widget
- User selects WalletConnect and approves connection
- Your app automatically detects the wallet and shows it in header
- User can now use both your app features and Layerswap swaps
Scenario 3: User Disconnects from Either Interface
- User has wallet connected
- User clicks “Disconnect” in either your app OR the widget
- Both interfaces update to show disconnected state
- Wallet state remains synchronized
Limitations
- EVM Only - Partial integration currently only works for EVM chains
- wagmi Required - Your app must already use wagmi
- Network Compatibility - Only Layerswap-supported EVM networks will be configured
- Native Wallet Packages for standard integration
- Custom Wallet Management for full control