> For the complete documentation index, see [llms.txt](https://leather.gitbook.io/developers/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://leather.gitbook.io/developers/methods/getaddresses.md).

# getAddresses

Request the Bitcoin addresses (Native SegWit and Taproot) and Stacks addresses for the active account of the user's wallet

## Method name

`getAddresses`

## Parameters

None

## Accounts

The number of the account connected by the user can be inferred by the `derivationPath` property for addresses returned in the response.&#x20;

Account values as indicated by derivation paths are one less than account values as represented in the wallet for users (i.e. the account value 6 corresponds to "Account 7").

In the example response below, the user has connected "Account 2" in their wallet (i.e. account value 1 per the derivation path).&#x20;

This account number can be used for the `account` parameter on the Bitcoin methods (`signMessage`, `sendTransfer`, `signPsbt`) to indicate the account for which to request them.

The Stacks methods do not take an `account` parameter. To indicate a Stacks request to a specific account, pass the `address` parameter with the STX address returned in the `getAddresses` response. This applies to `stx_callContract`, `stx_transferStx` and `stx_deployContract`.

If neither parameter is specified, the user's currently active account is used for fulfillment. That may not be the account your app is connected with.

{% hint style="warning" %}
**`getAddresses` is a connection request, not a query**

Every call to `getAddresses` re-runs the connection approval flow and opens a Connect app prompt. Leather does not resolve the call against a previous approval for the same origin, so the prompt is populated with the wallet's currently active account, which may not be the account your app is already connected with.

Call `getAddresses` once, on an explicit user action, and persist the returned addresses in your own app state. Do not call it to test whether a user is still connected, and do not call it immediately before a signing method.
{% endhint %}

{% hint style="info" %}
[Learn more about derivation paths](https://learnmeabitcoin.com/technical/derivation-paths)
{% endhint %}

## Example request

```typescript
function accountFromDerivationPath(path: string) {
  const segments = path.split("/");
  const account = parseInt(segments[3].replaceAll("'", ""), 10);
  if (isNaN(account)) throw new Error("Cannot parse account number from path");
  return account;
}

const response = await window.LeatherProvider?.request("getAddresses");

console.log("Addresses:", response.result.addresses);
console.log(
  "Account:",
  accountFromDerivationPath(response.result.addresses[0].derivationPath)
);
```

## Example response

```json5
{
    "jsonrpc": "2.0",
    "id": "288a4a32-899b-47da-ac43-b6adbb8caec2",
    "result": {
        "addresses": [
            {
                "symbol": "BTC",
                "type": "p2wpkh",
                "address": "bc1qetcn9fdtzq3wez6vrljjyry225ml7j52h3kwgl",
                "publicKey": "0328e268de2bd09f703b379d20b8a53fdc9c599a09a8c2fcd9c35e7b3cc48d0ece",
                "derivationPath": "m/84'/0'/1'/0/0"
            },
            {
                "symbol": "BTC",
                "type": "p2tr",
                "address": "bc1ph65ywff65f0nl84xaxwdxgc2rc2gpr70tptllffktt3qzyx859zsp3zvwl",
                "publicKey": "03482aa14965b71358082b110a30b91ef8dfbe6fbae3b18f5b841323f599b954f8",
                "tweakedPublicKey": "482aa14965b71358082b110a30b91ef8dfbe6fbae3b18f5b841323f599b954f8",
                "derivationPath": "m/86'/0'/1'/0/0"
            },
            {
                "symbol": "STX",
                "address": "SPY0682ZM7VGPMVGQP99Z05J3QWMVV83RA6N42SA"
            }
        ]
    }
}
```

{% hint style="warning" %}
**Do not read addresses by index e.g.** `result.addresses[2]`\
\
Developers must **not rely on elements being at a fixed index**. Ledger users may not have all keys, and more may be added in future. Accessing by index is not safe.\
\
Create a helper function using `Array.find` instead
{% endhint %}

## Example use case

You can use response data to store and retrieve data associated with any of the user's addresses.&#x20;

For example, you can query [mempool.space API](https://mempool.space/docs/api/rest#get-address) with a Bitcoin address for on-chain address details:

```typescript
const response = await window.LeatherProvider?.request("getAddresses");
const usersNativeSegwitAddress = response.result.addresses
  .find(address => address.type === 'p2wpkh');
const addressDetails = await fetch('https://mempool.space/api/address/' + usersNativeSegwitAddress)
```

## Sandbox

[Install the Leather extension](https://leather.io/install-extension) then try out this method below:

{% embed url="<https://codesandbox.io/embed/665l36?expanddevtools=1&hidenavigation=1&module=/index.html&view=preview>" %}

## Preview

<figure><img src="https://2085786563-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F41U87FfDFo2dIKYr0ZNX%2Fuploads%2FvyLMUjtrKRQ334qPFp1v%2FSCR-20240419-kykd.png?alt=media&amp;token=fc96cf43-21c6-48d6-b28a-e4fe47eca764" alt=""><figcaption></figcaption></figure>


---

# 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://leather.gitbook.io/developers/methods/getaddresses.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.
