> For the complete documentation index, see [llms.txt](https://docs.baas.sh/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.baas.sh/baas-sdk/authentication/external-wallet.md).

# External wallet

Sign users in with MetaMask, Rainbow, Coinbase Wallet, or any EIP-1193 wallet.

Pair BaaS with a wallet the user already has, such as MetaMask, Rainbow, or Coinbase Wallet. Their existing address becomes the BaaS account.

## Sign in

The same call covers first-time and returning users — the account is created on the first sign-in.

Pass an EIP-1193 provider such as `window.ethereum`, or a connector's provider from wagmi.

```ts
import type { EIP1193Provider } from '@baas.sh/sdk';

// MetaMask / browser-injected wallet
const provider = window.ethereum as EIP1193Provider | undefined;
if (!provider) {
  // No wallet detected. Prompt the user to install one, or disable the button.
  throw new Error('No wallet detected');
}
const session = await baas.auth.signInWithWallet(provider, { email: 'alice@example.com' });
```

```ts
// Any wagmi connector also works
const provider = await connector.getProvider();
const session = await baas.auth.signInWithWallet(provider, { email: 'alice@example.com' });
```

The user sees **two** wallet prompts (connect, unless the site is already connected, then sign the message). That's standard wallet UX.

## React to a disconnect or account switch

Signing in with a wallet creates a BaaS session, separate from the wallet's live connection.

The SDK watches the provider you signed in with. If the user disconnects your site or switches accounts in their wallet, the session ends: `onAuthStateChange` fires `SIGNED_OUT` and `getSession()` returns `null`.

After a page reload, call [`baas.chains.watchWallet(provider)`](/baas-sdk/blockchain/networks.md#follow-the-wallets-network-after-a-reload) so the SDK follows the wallet again.

## Next

* [Passkeys](/baas-sdk/authentication/passkeys.md) — sign in with the device's built-in authenticator.
* [Sessions](/baas-sdk/authentication/sessions.md) — read the session, listen for changes, and sign out.
* [Error handling](/baas-sdk/resources/error-handling.md) — handle a cancelled wallet prompt and network failures.
