Wagmi Connector

WalletPair ships a drop-in wagmi connector. If your dApp already uses wagmi, integration is a few lines.

Setup

wagmi.config.ts
import { walletPair } from 'walletpair-sdk/evm/wagmi';
import { createConfig, http } from '@wagmi/core';
import { mainnet, sepolia, polygon } from '@wagmi/core/chains';

const config = createConfig({
  chains: [mainnet, sepolia, polygon],
  connectors: [
    walletPair({
      relayUrl: 'wss://relay.walletpair.org/v1',
      onPairingUri: (uri) => {
        // Display QR code
        showQRCode(uri);
      },
      onSessionFingerprint: (fingerprint) => {
        // Display fingerprint for user verification
        showFingerprint(fingerprint);
      },
    }),
  ],
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
    [polygon.id]: http(),
  },
});

Connect and Use

typescript
import { connect, disconnect, signMessage, switchChain } from '@wagmi/core';

// Connect (triggers pairing flow)
const result = await connect(config, {
  connector: config.connectors[0],
});
console.log('Connected:', result.accounts);

// Sign a message
const signature = await signMessage(config, {
  message: 'Hello from wagmi!',
});

// Switch chain
await switchChain(config, { chainId: 137 });

// Disconnect
await disconnect(config);

When connect() is called, the connector creates a pairing and calls your onPairingUri callback. Display the URI as a QR code. Once the wallet scans and joins, the connection resolves.

Watch for Changes

typescript
import { watchAccount, watchChainId } from '@wagmi/core';

watchAccount(config, {
  onChange: (account) => {
    console.log('Account changed:', account.address);
  },
});

watchChainId(config, {
  onChange: (chainId) => {
    console.log('Chain changed:', chainId);
  },
});

EIP-1193 Provider

If you're not using wagmi, you can use the standalone EIP-1193 provider directly:

typescript
import { WalletPairProvider } from 'walletpair-sdk/evm/eip1193';

// Create an EIP-1193 provider from an existing DAppSession
const provider = new WalletPairProvider({ session: dAppSession });

// Standard EIP-1193 interface
const accounts = await provider.request({ method: 'eth_accounts' });
const signature = await provider.request({
  method: 'personal_sign',
  params: ['0x48656c6c6f', accounts[0]],
});

// Provider events
provider.on('accountsChanged', (accounts) => { /* ... */ });
provider.on('chainChanged', (chainId) => { /* ... */ });

RPC Method Routing

The provider only sends wallet operations (signing, accounts, chain switching) through WalletPair. Read-only RPC methods (eth_call, eth_getBalance, etc.) are routed to your dApp's own RPC provider — they never touch the wallet.