Manage Accounts
Retrieve Spark accounts by index and iterate over them.
This guide explains how to retrieve accounts by index, retrieve accounts by derivation path, and iterate over accounts.
Retrieve Accounts by Index
- Call
wallet.getAccount()with the account index. - Call
account.getAddress()for each account.
You can retrieve multiple accounts using wallet.getAccount() with different index values:
const account0 = await wallet.getAccount(0)
const address0 = await account0.getAddress()
console.log('Account 0 address:', address0)
const account1 = await wallet.getAccount(1)
const address1 = await account1.getAddress()
console.log('Account 1 address:', address1)Accounts use BIP-44 paths m/44'/998'/{networkNumber}'/0/{index} where 998 is Spark’s coin type and networkNumber is 0 for MAINNET, 2 for SIGNET, or 3 for REGTEST.
Retrieve Accounts by Derivation Path
You can retrieve an account at a specific BIP-44 derivation path using wallet.getAccountByPath():
const account = await wallet.getAccountByPath("0'/0/0")
const address = await account.getAddress()
console.log('Account address:', address)The path segment is appended to the base path m/44'/998'/. For example, "0'/0/0" resolves to m/44'/998'/0'/0/0 on MAINNET. See getAccountByPath() in the API reference.
Iterate Over Accounts
You can walk a range of indices using wallet.getAccount() inside a loop:
for (let i = 0; i < 5; i++) {
const account = await wallet.getAccount(i)
const address = await account.getAddress()
const balance = await account.getBalance()
console.log(`Account ${i}: ${address} (${balance} satoshis)`)
}Next Steps
With accounts set up, learn how to check balances.