> 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> |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs-wallet.magiceden.io/bitcoin/connecting-to-the-wallet.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
