Connect wallets
Wallets & accounts connection can by managed via useWallets, useConnectedWallets & useAccounts hooks.
If you prefer not having to build a wallet connection UI from scratch, checkout DOTConnect for a quick and easy way to add a great wallet experience to your DApps.
Install optional dependencies
Additional dependencies are required if you use any of be bellow wallet type.
Plug-and-play wallets
WalletConnect
- npm
- Yarn
- pnpm
- Bun
npm install @reactive-dot/wallet-walletconnect
yarn add @reactive-dot/wallet-walletconnect
pnpm add @reactive-dot/wallet-walletconnect
bun add @reactive-dot/wallet-walletconnect
Mimir
- npm
- Yarn
- pnpm
- Bun
npm install @reactive-dot/wallet-mimir
yarn add @reactive-dot/wallet-mimir
pnpm add @reactive-dot/wallet-mimir
bun add @reactive-dot/wallet-mimir
Wallets requiring additional UI setup
The wallets listed below require extra UI integration and platform-specific setup. To avoid implementing these flows yourself, we recommend using DOTConnect for a quick and reliable wallet integration.
Polkadot Vault
- npm
- Yarn
- pnpm
- Bun
npm install @reactive-dot/wallet-polkadot-vault
yarn add @reactive-dot/wallet-polkadot-vault
pnpm add @reactive-dot/wallet-polkadot-vault
bun add @reactive-dot/wallet-polkadot-vault
Ledger
- npm
- Yarn
- pnpm
- Bun
npm install @reactive-dot/wallet-ledger
yarn add @reactive-dot/wallet-ledger
pnpm add @reactive-dot/wallet-ledger
bun add @reactive-dot/wallet-ledger
Readonly
- npm
- Yarn
- pnpm
- Bun
npm install @reactive-dot/wallet-readonly
yarn add @reactive-dot/wallet-readonly
pnpm add @reactive-dot/wallet-readonly
bun add @reactive-dot/wallet-readonly
Add wallets to the config
import { defineConfig } from "@reactive-dot/core";
import { InjectedWalletProvider } from "@reactive-dot/core/wallets.js";
import { LedgerWallet } from "@reactive-dot/wallet-ledger";
import { MimirWalletProvider } from "@reactive-dot/wallet-mimir";
import { PolkadotVaultWallet } from "@reactive-dot/wallet-polkadot-vault";
import { WalletConnect } from "@reactive-dot/wallet-walletconnect";
export const config = defineConfig({
// ...
wallets: [
new InjectedWalletProvider(),
new LedgerWallet(),
new MimirWalletProvider(),
new PolkadotVaultWallet(),
new WalletConnect({
projectId: "WALLET_CONNECT_PROJECT_ID",
providerOptions: {
metadata: {
name: "APP_NAME",
description: "APP_DESCRIPTION",
url: "APP_URL",
icons: ["APP_ICON"],
},
},
chainIds: [
// https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-13.md
"polkadot:91b171bb158e2d3848fa23a9f1c25182", // Polkadot
// ...
],
}),
],
});
Connect to wallets
import {
useConnectedWallets,
useWallets,
useWalletConnector,
useWalletDisconnector,
} from "@reactive-dot/react";
export function Wallets() {
const wallets = useWallets();
const connectedWallets = useConnectedWallets();
const [_, connectWallet] = useWalletConnector();
const [__, disconnectWallet] = useWalletDisconnector();
return (
<section>
<header>
<h3>Wallet connection</h3>
</header>
<article>
<h4>Wallets</h4>
<ul>
{wallets.map((wallet) => (
<li key={wallet.id}>
<div>{wallet.name}</div>
<div>
{connectedWallets.includes(wallet) ? (
<button onClick={() => disconnectWallet(wallet)}>
Disconnect
</button>
) : (
<button onClick={() => connectWallet(wallet)}>Connect</button>
)}
</div>
</li>
))}
</ul>
</article>
</section>
);
}
Display available accounts
import { useAccounts } from "@reactive-dot/react";
export function Accounts() {
const accounts = useAccounts();
return (
<section>
<header>
<h3>Accounts</h3>
</header>
<ul>
{accounts.map((account, index) => (
<li key={index}>
<div>{account.address}</div>
<div>{account.name}</div>
</li>
))}
</ul>
</section>
);
}
By default the useAccounts hook will only return accounts that are compatible with the current chain (i.e. as set by ChainProvider).
If you want to get all accounts regardless of the current chain, you can pass null as the chainId option to the useAccounts hook:
useAccounts({ chainId: null });