Using the Storage Module in Services Kit Core Client

The Storage Module provides a way to interact with Ledger Live’s internal storage. You can store and retrieve data using key-value pairs.

Storage Module Overview

Access the Storage module via walletApiClient.storage.

Methods:

1. Get Data

Retrieve data from Ledger Live’s internal storage by specifying a key. You can also specify a store ID to retrieve data from a particular store.

walletApiClient.storage.get(key: string, storeId?: string): Promise<string | undefined>

Parameters:

  • key (required): A string representing the key of the data you want to retrieve.
  • storeId (optional): A string representing the ID of the store from which you want to retrieve data.

Returns: A promise that resolves with the value as a string or undefined if the key does not exist.

Required permission: storage.get

Example:
async function getData(walletApiClient, key, storeId) {
  try {
    const value = await walletApiClient.storage.get(key, storeId);
    console.log('Retrieved Value:', value);
  } catch (error) {
    console.error('Error retrieving data:', error);
  }
}

2. Set Data

Store data in Ledger Live’s internal storage. You can specify a key and value, and optionally provide a store ID to store data in a specific store.

walletApiClient.storage.set(key: string, value: string, storeId?: string): Promise<void>

Parameters:

  • key (required): A string representing the key under which you want to store the data.
  • value (required): A string representing the data you want to store.
  • storeId (optional): A string representing the ID of the store where you want to store the data.

Returns: A promise that resolves when the data is successfully stored. There is no return value.

Required permission: storage.set

Example:
async function setData(walletApiClient, key, value, storeId) {
  try {
    await walletApiClient.storage.set(key, value, storeId);
    console.log('Data successfully stored.');
  } catch (error) {
    console.error('Error storing data:', 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 Services Kit to free up resources.

Ledger
Copyright © Ledger SAS. All rights reserved. Ledger, Ledger Nano S, Ledger Vault, Ledger OS are registered trademarks of Ledger SAS