Web3 wallet connection for Svelte 5 applications using ethers v6 and WalletConnect v2.
npm install svelteconnect @walletconnect/ethereum-provider ethers
<script>
import { ConnectButton, wallet } from 'svelteconnect';
</script>
<ConnectButton projectId="YOUR_WALLETCONNECT_PROJECT_ID" />
{#if wallet.address}
<p>Connected: {wallet.address}</p>
{/if}
| Prop | Type | Default | Description |
|---|---|---|---|
projectId |
string |
required | WalletConnect Cloud project ID |
chains |
number[] |
[1] |
Required chains (default: Ethereum mainnet) |
optionalChains |
number[] |
[1, 137, 56, 42161, 10] |
Optional chains |
metadata |
object |
auto | App metadata for WalletConnect |
class |
string |
'' |
Custom CSS class |
Access wallet state anywhere via the wallet store:
<script>
import { wallet } from 'svelteconnect';
</script>
{wallet.address} <!-- Connected address or null -->
{wallet.chainId} <!-- Current chain ID -->
{wallet.provider} <!-- ethers BrowserProvider -->
{wallet.isConnecting}
{wallet.error}
import { connect, disconnect, cancelConnect, configure } from "svelteconnect";
connect(); // Start connection
disconnect(); // Disconnect wallet
cancelConnect(); // Cancel ongoing connection
configure({ projectId, chains, optionalChains, metadata }); // Manual config
GPLv3