Appearance
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
| Option | Meaning |
|---|---|
provider | Wallet provider to bind |
Returns
| Field | Meaning |
|---|---|
provider | The provider passed into the hook |
wallet | Matching AvailableWallet, or null if it is not in the list |
connections | Connected instances of this provider |
isConnected | At least one instance is connected |
isConnecting | Connect is in flight for this provider |
error | Last 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 |
requiresDeepLink | Open-in-wallet-app path on this device |
supportsWalletConnect | WalletConnect is offered |
getDeepLinkUrl() | Browse URL, or null |
openDeepLink() | Opens that URL; returns it or null |
cancelPairing() | Abort in-flight WalletConnect pairing |
pairingUri | Current WalletConnect URI while this provider is pairing, or null |
pairingDeeplinkUrl | Current 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).