wallet_getAccount
Fetch the user's Xverse wallet account
Your app can fetch the user's active Xverse account with the wallet_getAccount method.
The app must have first connected to the wallet and obtained account read permissions.
You can optionally specify which wallet addresses you require: Bitcoin ordinals address, Bitcoin payment address, Spark, Starknet or Stacks address, using the optional
addressesrequest parameter.
addresses
ℹ️ Optional
an array of strings used to specify which address(es) to request from the user's Xverse wallet account:
'ordinals'is preferably used to manage the user’s ordinals
'payment'is preferably used to manage the user’s bitcoin
'stacks'is used to interact with the stacks ecosystem'spark'is used to interact with the Spark ecosystem'starknet'is used to interact with the Starknet ecosystem
Example: ['ordinals', 'payment', 'stacks']
Will default to ['ordinals', 'payment', 'stacks', 'spark','starknet'] if not specified.
import Wallet from 'sats-connect';
const response = await Wallet.request('wallet_getAccount', null);
if (response.status === 'error') {
console.error(response.error);
return;
}
console.log(response.result);The wallet_getAccount method attempts to fetch the user's active Xverse account directly. You can use it to grant your connected user a smooth experience, without connection popups.
✅ getAccount Result - account is connected
If your user has already connected their active Xverse account to your app, and granted your app the necessary account read permissions -> the method successfully returns getAccountResult:
The account id
The wallet type (software or hardware)
an array of the user’s wallet address objects, defined as:
type address = {
address: string;
publicKey: string;
purpose: "payment" | "ordinals" | "stacks" | "spark" | "starknet";
addressType: "p2tr" | "p2wpkh" | "p2sh" | "stacks" | "spark" | "starknet";
}You can use these addresses to make further requests such as signing a message, signing a transaction, 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:
{
walletType: "software",
id: "dj0f7g5xtdakgecvf45dvssu66",
addressses: [
{
address: "tb1pzwa68q3udj0f7g5xtdakgecvf45dvssu66ry7y3at22w7vus20vq3sgw62",
publicKey: "b9907521ddb85e0e6a37622b7c685efbdc8ae53a334928adbd12cf204ad4e717",
purpose: "ordinals",
addressType: "p2tr",
network: 'mainnet'
},
{
address: "2NBfRKCUpafbatj5gV9T82uau3igdSf9BXJ",
publicKey: "02818b7ff740a40f311d002123087053d5d9e0e1546674aedb10e15a5b57fd3985",
purpose: "payment",
addressType: "p2sh",
network: 'mainnet'
}
]
}Where:
walletType
string - the type of wallet used for the account
ledgerif the user's account is using a Ledger devicesoftwareotherwise
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 bitcoinstacksis used to interact with the stacks ecosystem
addressType
string - the address’s format:
P2TRfor ordinalsP2SHfor paymentP2WPKHfor payment using Ledgerstacksfor Stacks
sparkfor Sparkstarknetfor Starknet
network
string - the network where the address is being used:
Mainnetfor Bitcoin Mainnet | Spark Mainnet | Stacks Mainnet | Starknet MainnetRegtestfor Bitcoin Regtest | Spark Regtest | Stacks Testnet | Starknet SepoliaTestnetfor Bitcoin Testnet | Spark Regtest | Stacks Testnet | Starknet SepoliaSignetfor Bitcoin Signet | Spark Regtest | Stacks Testnet | Starknet Sepolia
❌ getAccount Result - account is not connected
If your user has not connected their active Xverse account to your app yet, and your app does not the necessary account read permissions -> the method will throw with an access denied error
You can use the connect or wallet_requestPermissions methods to request a connection to your user's active Xverse account.
Last updated