getAddresses
Your app can request the current account's Bitcoin addresses with getAddresses. The app must have first connected to the wallet and obtained account read permissions.
Apps can specify which wallet addresses they require: Bitcoin ordinals address or Bitcoin payment address, using the
purposesrequest parameterThe
messagerequest param gives apps the option to display a message the user when requesting their addresses.
purposes
Array of strings used to specify the purpose of the address(es) to request:
'ordinals'is preferably used to manage the user’s ordinals
'payment'is preferably used to manage the user’s bitcoin
Example: ['ordinals', 'payment']
message
ℹ️ Optional a message to be displayed to the user in the request prompt.
import { request } from "sats-connect";
try {
const response = await request("getAddresses", 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);
}Once resolved, the method returns GetAddressResult: an array of the user’s wallet address objects, defined as:
type address = {
address: string;
publicKey: string;
purpose: "payment" | "ordinals"
addressType: "p2tr" | "p2wpkh" | "p2sh"
}You can use these addresses to make further requests such as signing a message, signing a transaction, etc.
Currently, apps 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:
GetAddressesResult: [
{
address: "tb1pzwa68q3udj0f7g5xtdakgecvf45dvssu66ry7y3at22w7vus20vq3sgw62",
publicKey: "b9907521ddb85e0e6a37622b7c685efbdc8ae53a334928adbd12cf204ad4e717",
purpose: "ordinals",
addressType: "p2tr",
walletType: "software"
},
{
address: "2NBfRKCUpafbatj5gV9T82uau3igdSf9BXJ",
publicKey: "02818b7ff740a40f311d002123087053d5d9e0e1546674aedb10e15a5b57fd3985",
purpose: "payment",
addressType: "p2sh",
walletType: "software"
}
]Where:
address
string - the user’s connected wallet address
publicKey
A hex string representing the bytes of the public key of the account. You can use this to construct partially signed Bitcoin transactions (PSBT).
purpose
string - The purpose of the address:
ordinalsis preferably used to manage the user’s ordinalspaymentis preferably used to manage the user’s bitcoin
addressType
string - the address’s format:
P2TRfor ordinalsP2SHfor paymentP2WPKHfor payment using Ledger
network
string - the network where the address is being used:
mainnetfor Bitcoin Mainnettestnetfor Bitcoin TestnetSignetfor Bitcoin Signet
walletType
string - the type of wallet used for the account
ledgerif the user's account is using a Ledger devicesoftwareotherwise
Last updated