Documentation
Core
Modules
Account

Using the Account Module in Wallet API Core Client

The Account Module allows you to interact with the user's accounts. You can list accounts, request an account, and verify account addresses on a Ledger device through Ledger Live.

Account Module Overview

Access the Account module via walletApiClient.account.

Methods:

1. List Accounts

Retrieve the list of accounts added by the user on the connected wallet. You can filter the accounts by currency IDs.

walletApiClient.account.list(params?: { currencyIds?: string[] }): Promise<Account[]>

Parameters:

  • params (optional): An object that may contain:
  • currencyIds (optional): An array of strings specifying the currency IDs to filter accounts by.

Returns: A promise that resolves with an array of Account objects.

Required permission: (opens in a new tab) account.list

Example:
async function listAccounts(walletApiClient) {
  try {
    const accounts = await walletApiClient.account.list();
    console.log('All Accounts:', accounts);
 
    const bitcoinAccounts = await walletApiClient.account.list({ currencyIds: ['bitcoin'] });
    console.log('Bitcoin Accounts:', bitcoinAccounts);
  } catch (error) {
    console.error('Error listing accounts:', error);
  }
}

2. Request Account

Prompt the user to select an account from the connected wallet. You can filter the accounts by currency IDs.

walletApiClient.account.request(params?: { currencyIds?: string[] }): Promise<Account>

Parameters:

  • params (optional): An object that may contain:
  • currencyIds (optional): An array of strings specifying the currency IDs to filter accounts by. You can find currency IDs and token IDs in the Ledger repository (opens in a new tab).

Returns: A promise that resolves with the selected Account object.

Required permission: (opens in a new tab) account.request

Example:
async function requestAccount(walletApiClient) {
  try {
    const account = await walletApiClient.account.request({ currencyIds: ['ethereum'] });
    console.log('Selected account:', account);
  } catch (error) {
    console.error('Error requesting account:', error);
  }
}

3. Verify Account Address

Allows the user to verify an account's address on their Ledger device through Ledger Live.

walletApiClient.account.receive(accountId: string): Promise<string>

Parameters:

  • accountId (required): The ID of the account whose address needs to be verified.

Returns: A promise that resolves with the verified address as a string.

Required permission: (opens in a new tab) account.receive

Example:
async function verifyAccountAddress(walletApiClient, accountId) {
  try {
    const address = await walletApiClient.account.receive(accountId);
    console.log('Verified address:', address);
  } catch (error) {
    console.error('Error verifying account address:', error);
  }
}

Handling Errors

Make sure to handle errors gracefully and provide appropriate feedback to the user. Additionally, always remember to disconnect the WindowMessageTransport when you're done interacting with the Ledger Wallet API to free up resources.