> 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

## 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 while requesting other methods to indicate the account for which to request them (e.g. for signing transactions with a particular account).

If an `account` parameter is not specified while requesting other methods, the user's currently active account will be used for fulfillment.

{% 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="/files/sAuvZ2p26eXiIEVpt2fF" 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.
