Skip to content

useWallet ​

Connect / disconnect and status for one wallet provider (MetaMask, Phantom, …). Requires WalletsProvider.

provider is the brand. One provider can have more than one connection (walletId). For actions across every provider (or when you do not have a provider yet), use useConnectWallet. Options and errors: Connect wallet (Core).

Example ​

tsx
import { IntegrationProvider } from '@swapped/connect-sdk'
import { useWallet } from '@swapped/connect-sdk/react'

function MetaMaskRow() {
  const {
    wallet,
    connect,
    disconnect,
    isConnecting,
    isConnected,
    error,
  } = useWallet(IntegrationProvider.MetaMask)

  return (
    <div>
      <button
        type="button"
        disabled={isConnecting}
        onClick={() =>
          void (isConnected
            ? disconnect()
            : connect({ transport: 'injected', popupIfUnavailable: true }))
        }
      >
        {isConnected ? 'Disconnect' : 'Connect'} {wallet?.name ?? 'MetaMask'}
      </button>
      {error}
    </div>
  )
}

Options ​

OptionMeaning
providerWallet provider to bind

Returns ​

FieldMeaning
providerThe provider passed into the hook
walletMatching AvailableWallet, or null if it is not in the list
connectionsConnected instances of this provider
isConnectedAt least one instance is connected
isConnectingConnect is in flight for this provider
errorLast error message for this provider, or null
connect(request?)Promise<WalletConnection | null>. Same options as Core, minus provider
disconnect(walletId?)One instance, or every instance of this provider when omitted
requiresDeepLinkOpen-in-wallet-app path on this device
supportsWalletConnectWalletConnect is offered
getDeepLinkUrl()Browse URL, or null
openDeepLink()Opens that URL; returns it or null
cancelPairing()Abort in-flight WalletConnect pairing
pairingUriCurrent WalletConnect URI while this provider is pairing, or null
pairingDeeplinkUrlCurrent WalletConnect mobile deep link while this provider is pairing, or null

Transports and errors ​

Same as useConnectWallet: omit transport to let the SDK pick injected vs WalletConnect; connect / disconnect reject with ConnectSdkError. See Errors and Connect wallet (Core).