> For the complete documentation index, see [llms.txt](/llms.txt)

# Connect Wallet

Programmatically connect to a Sui wallet



The dApp Kit SDK provides an action for wallet connection, allowing users to connect, disconnect,
and switch between wallets and accounts.

<Callout>
  The [Connect Button](../web-components/connect-button) Web Component provides a complete wallet
  connection UI.
</Callout>

## Usage

<Callout>
  Auto-connect is enabled by default and will attempt to restore the previous wallet connection on
  page reload. This provides a seamless user experience but can be
  [disabled](../dapp-kit-instance#disabling-auto-connect) if needed.
</Callout>

The `connectWallet` action prompts a wallet to connect and authorize accounts for your application:

```typescript
import { createDAppKit } from '@mysten/dapp-kit-core';

const dAppKit = createDAppKit({
	/* config */
});

// Connect to a specific wallet
const result = await dAppKit.connectWallet({
	wallet: myWallet, // UiWallet instance
	account: myAccount, // Optional: specific account to select
});

console.log('Connected accounts:', result.accounts);
```

## Parameters

* **`wallet`** - The `UiWallet` instance to connect to
* **`account`** (optional) - A specific `UiWalletAccount` to set as the selected account. Defaults
  to the first authorized account

## Return Value

Returns a `Promise` that resolves to an object containing:

* **`accounts`** - Array of authorized `UiWalletAccount` instances

## Example

```typescript
const wallets = dAppKit.stores.$wallets.get();

const unsubscribe = dAppKit.stores.$connection.subscribe((connection) => {
	if (connection.isConnected) {
		console.log(`Connected account address: ${connection.account.address}`);
	} else {
		console.log({ connection });
	}
});

if (wallets.length > 0) {
	try {
		const { accounts } = await dAppKit.connectWallet({
			wallet: wallets[0],
		});
		console.log('Available accounts:', accounts);
	} catch (error) {
		console.error('Connection failed:', error);
	}
}
```
