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

# Connect Wallet

Learn how to integrate wallet connections into your Stacks application. Connecting a wallet authenticates users and enables blockchain interactions like transfers and contract calls.

<div data-with-frame="true"><figure><img src="https://284917788-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZz9BLmTU9oydDpL3qiUh%2Fuploads%2Fgit-blob-521c9e1b18c41dfdbdc4898a1744128bb0586128%2Fstacks-connect.jpg?alt=media" alt=""><figcaption></figcaption></figure></div>

{% hint style="success" %}
For the latest releases and versions of `@stacks/connect`, check out its npm page [here](https://www.npmjs.com/package/@stacks/connect).
{% endhint %}

## What you'll learn

* Install the `@stacks/connect` package
* Connect to a wallet and authenticate users
* Manage authentication state
* Access user account data

{% hint style="info" %}
Prerequisites:

* Node.js installed on your machine
* A web application setup (React, Vue, or vanilla JS)
* Basic understanding of async/await
  {% endhint %}

## Quickstart

{% stepper %}
{% step %}
**Install package**

Add Stacks Connect to your project:

{% code title="Install" %}

```bash
npm install @stacks/connect
```

{% endcode %}
{% endstep %}

{% step %}
**Connect and authenticate**

Use `connect` to initiate a wallet session and persist user data:

{% code title="connect.ts" %}

```ts
import { connect, isConnected } from '@stacks/connect';

async function connectWallet() {
  if (isConnected()) {
    console.log('Already authenticated');
    return;
  }

  const response = await connect();
  console.log('Connected:', response.addresses);
}
```

{% endcode %}

Manage authentication state in your app:

{% code title="auth.ts" %}

```ts
import { disconnect, isConnected } from '@stacks/connect';

const authenticated = isConnected();

function logout() {
  disconnect();
  console.log('User disconnected');
}
```

{% endcode %}
{% endstep %}

{% step %}
**Access user data**

Read persisted addresses and request full account details:

{% code title="user-data.ts" %}

```ts
import { getLocalStorage, request } from '@stacks/connect';

const userData = getLocalStorage();
if (userData?.addresses) {
  const stxAddress = userData.addresses.stx[0].address;
  const btcAddress = userData.addresses.btc[0].address;
  console.log('STX:', stxAddress);
  console.log('BTC:', btcAddress);
}

const accounts = await request('stx_getAccounts');
const account = accounts.addresses[0];
console.log('Address:', account.address);
console.log('Public key:', account.publicKey);
console.log('Gaia URL:', account.gaiaHubUrl);
```

{% endcode %}
{% endstep %}

{% step %}
**Make your first transaction**

Request the wallet to broadcast a transfer:

{% code title="send-transaction.ts" %}

```ts
import { request } from '@stacks/connect';

async function sendTransaction() {
  const response = await request('stx_transferStx', {
    amount: '1000000',
    recipient: 'SP2MF04VAGYHGAZWGTEDW5VYCPDWWSY08Z1QFNDSN',
    memo: 'First transfer',
  });

  console.log('Transaction ID:', response.txid);
}
```

{% endcode %}
{% endstep %}
{% endstepper %}


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.stacks.co/stacks-connect/connect-wallet.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
