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

# Connecting to the Wallet

## Connect Wallet

This function is designed to initiate the connection process to a user's Bitcoin wallet. It leverages the [Sats Connect getAddress API](https://docs.xverse.app/sats-connect-v1/methods/getaddress) to request a user's payment address (native segwit) and ordinals/runes address (taproot).&#x20;

It makes use of the `getBtcProvider` method we defined in [Detecting the Provider](/bitcoin/detecting-the-provider.md).

```typescript
import { getAddress, AddressPurpose, BitcoinNetworkType } from "sats-connect";

async function connectOrDeselect() {
	await getAddress({
		getProvider: getBtcProvider,
		payload: {
			purposes: [AddressPurpose.Ordinals, AddressPurpose.Payment],
			message: "Address for receiving Ordinals and payments",
			network: {
				type: BitcoinNetworkType.Mainnet,
			},
		},
		onFinish: (response) => {
			console.log("onFinish response, ", response.addresses);
	
			// do some action like updating your app context
			connectionStatus?.setAccounts(response.addresses as unknown as Account[]);
		},
		onCancel: () => {
			alert("Request canceled");
		},
	});
}
```

The `getAddresss` method returns a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) that resolves if the user approves the connection request.

<figure><img src="/files/OeOOstVfeGE0jrvEaKKl" alt=""><figcaption></figcaption></figure>

Once resolved, the method returns an array of the user’s wallet address objects, defined as:

```typescript
type address = {
    address: string;
    publicKey: string;
    purpose: "payment" | "ordinals";
}
```

Where:

| address field | Description                                                                                                                                                                       |
| ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `address`     | The user’s connected  address                                                                                                                                                     |
| `publicKey`   | A hex string representing the bytes of the public key of the account.                                                                                                             |
| `purpose`     | <p>The purpose of the address:</p><ul><li><code>payment</code> is used to manage the user’s bitcoin</li><li><code>ordinals</code> is used to manage the user’s ordinals</li></ul> |
