Links
Comment on page
🏡

Get addresses

Request BTC and STX addresses from a user's wallet
This method serves as an alternative to authenticating users. It provides access to Native SegWit, Taproot and Stacks addresses on index 0 for the wallet's active account. It also conforms to the btckit .request standard.

Code example

You can request a user's addresses with the getAddresses method.
const userAddresses = await window.btc?.request('getAddresses');
This returns an RPC response
{
"jsonrpc": "2.0",
"id": "a286835f-8bc7-4d4b-8e5c-31437cbb4e8b",
"result": {
"addresses": [
{
"symbol": "BTC",
"type": "p2wpkh",
"address": "bc1q…3y6ms",
"publicKey": "0224…590b",
"derivationPath": "m/84'/0'/4/0/0"
},
{
"symbol": "BTC",
"type": "p2tr",
"address": "bc1p…v6w",
"publicKey": "0233…c7fa",
"derivationPath": "m/86'/0'/4/0/0"
},
{
"symbol": "STX",
"address": "SPGH…W1QF"
}
]
}
}
You can infer information about the account the user authenticated with from the derivationPath property. Here, we can see the user connected the account on the 4th index.
You might use this information for later requests, or to show details of a user's address. This code examples shows how you might query the mempool.space API.
const usersNativeSegwitAddress = userAddresses.results.addresses
.find(address => address.type === 'p2wpkh');
const addressDetails = await fetch('https://mempool.space/api/address/' + usersNativeSegwitAddress)

Example screenshot