# \[Legacy ⚠️] getAccounts

{% hint style="warning" %}
**🚀 Attention Developers: Upgrade to the** [**connect**](/sats-connect/connecting-to-the-wallet.md) **method 🚀**

A new [connect](/sats-connect/connecting-to-the-wallet.md) method is now available to connect to user's wallets and request permissions to access their accounts.&#x20;

While the legacy version documented here remains supported, we urge you to upgrade for access to the latest features and a more smoother user experience.
{% endhint %}

Your application can request to connect to the user’s wallet with the `getAccounts` method, which prompts them to share their Bitcoin and Stacks addresses.

* You can specify which wallet addresses you require, Bitcoin ordinals address, Bitcoin payment address or Stacks address, using the `purposes` request parameter
* The `message` request param gives you the option to display a message the user when requesting their addresses. You can use it to present your app and explain why you require access to their addresses.

<table><thead><tr><th width="205">request parameters</th><th>Description</th></tr></thead><tbody><tr><td><code>purposes</code></td><td><p>Array of strings used to specify the purpose of the address(es) to request:</p><ul><li><code>'ordinals'</code> is preferably used to manage the user’s ordinals</li><li><code>'payment'</code> is preferably used to manage the user’s bitcoin</li><li><code>'stacks'</code> is used to interact with the stacks ecosystem</li></ul><p>Example: <code>['ordinals', 'payment', 'stacks']</code> </p></td></tr><tr><td><code>message</code></td><td><span data-gb-custom-inline data-tag="emoji" data-code="2139">ℹ️</span> Optional<br>a message to be displayed to the user in the request prompt.</td></tr></tbody></table>

{% code fullWidth="false" %}

```typescript
import {request} from "sats-connect";

try {

  const response = await request('getAccounts', null);
  console.log("getAccounts ~ response:", response)
  if (response.status === 'success') {
    const paymentAddressItem = response.result.find(
      (address) => address.purpose === AddressPurpose.Payment
    );
    const ordinalsAddressItem = response.result.find(
      (address) => address.purpose === AddressPurpose.Ordinals
    );
    const stacksAddressItem = response.result.find(
        (address) => address.purpose === AddressPurpose.Stacks
    );
  } else {
    if (response.error.code === RpcErrorCode.USER_REJECTION) {
      // handle user cancellation error
    } else {
      // handle error
    }
  }
} catch (err) {
    alert(err.error.message);
}
```

{% endcode %}

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. The user will see a *Connection Request* prompt in their wallet. The prompt will display:

* your app logo, if it is specified in your app manifest
* the wallet addresses that your app required
* the message which you specified. Note that this message will be cut beyond 80 characters.

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

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

```typescript
type address = {
    address: string;
    publicKey: string;
    purpose: "payment" | "ordinals" | "stacks";
    addressType: "p2tr" | "p2wpkh" | "p2sh" | "stacks";
}
```

You can use these addresses to make further requests such as [signing a message](/sats-connect/bitcoin-methods/signmessage.md), [signing a transaction](/sats-connect/bitcoin-methods/signpsbt.md), etc.

Currently, you can retrieve two types of Bitcoin addresses, the user's Bitcoin payment address and the Ordinals address which is a taproot address.

An example response:

```typescript
GetAccountResult: [
  {
    address: "tb1pzwa68q3udj0f7g5xtdakgecvf45dvssu66ry7y3at22w7vus20vq3sgw62",
    publicKey: "b9907521ddb85e0e6a37622b7c685efbdc8ae53a334928adbd12cf204ad4e717",
    purpose: "ordinals",
    addressType: "p2tr",
    walletType: "software"
  },
  {
    address: "2NBfRKCUpafbatj5gV9T82uau3igdSf9BXJ",
    publicKey: "02818b7ff740a40f311d002123087053d5d9e0e1546674aedb10e15a5b57fd3985",
    purpose: "payment",
    addressType: "p2sh",
    walletType: "software"
  }
]
```

Where:

<table><thead><tr><th width="162">address field</th><th>Description</th></tr></thead><tbody><tr><td><code>address</code> </td><td>string - the user’s connected wallet address</td></tr><tr><td><code>publicKey</code></td><td>A hex string representing the bytes of the public key of the account. You can use this to construct partially signed Bitcoin transactions (PSBT).</td></tr><tr><td><code>purpose</code></td><td><p>string - The purpose of the address:</p><ul><li><code>ordinals</code> is preferably used to manage the user’s ordinals</li><li><code>payment</code> is preferably used to manage the user’s bitcoin</li><li><code>stacks</code> is used to interact with the stacks ecosystem</li></ul></td></tr><tr><td><code>addressType</code></td><td><p>string - the address’s format:</p><ul><li><code>P2TR</code> for ordinals</li><li><code>P2SH</code> for payment</li><li><code>P2WPKH</code> for payment using Ledger</li><li><code>stacks</code> for Stacks</li></ul></td></tr><tr><td><code>walletType</code></td><td><p>string - the type of wallet used for the account</p><ul><li><code>ledger</code> if the user's account is using a Ledger device</li><li><code>software</code> otherwise</li></ul></td></tr></tbody></table>

If the user declines the request or closes the pop-up, the promise will reject (throw when awaited).


---

# Agent Instructions: 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:

```
GET https://docs.xverse.app/sats-connect/connecting-to-the-wallet/legacy-getaccounts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
