Skip to main content

Store a Wallet on a Remote Drive

This section of the documentation focuses on the importance of storing a wallet.

Overview​

During the development of a web application that incorporates a wallet, you can choose to store it in the browser's local storage. This default storage approach makes the implementation of the wallet easier for developers, thus streamlining the testing process and the development of new features.

Risks of Storing a Wallet in a Web Browser's Local Storage

However, it is crucial to understand that this method of storing the wallet in local storage MUST NOT be used in a production environment. Local storage does not provide the necessary security measures to protect sensitive data such as wallet keys share and can be easily lost if the browser cache is cleared.

For a production application, it is highly recommended to use a more reliable storage method, such as a remote drive (e.g., Google Drive or Dropbox). These remote storage solutions provide robust security features, data encryption, and backup options, ensuring the safety and accessibility of the wallet data.

Storing a Wallet​

In this code snippet, we demonstrate how to set up and utilize the SDK for storing a wallet. The script initiates the SDK with a provided client ID, stores the wallet to the user's Google Drive. This serves as a foundation example for developers who are looking to build and manage a wallet using the SDK.

Live Editor

Retrieving a Wallet​

Retrieving the wallet is completely transparent to the developer, as it is integrated into the instantiate method of the Wallet namespace.

References​

  1. Eniblock class
  2. WalletNamespace.instantiate() method
  3. AccountNamespace.get() method
  4. Account.getAddress() method
  5. Account.alias property
  6. Account.getNativeBalance() method
  7. Account.getPublicKey() method
  8. Account.creationDate property

Store a wallet with Google Drive​

Step 1: Create a Google Cloud Platform (GCP) Project​

  1. Visit the Google Cloud Platform Console.

  2. Sign in with your Google account or create a new account if you don't have one.

  3. Click on the project dropdown and select or create the project you want to use for your web app.

    gcp_create_project_1
    Click on the project dropdown
    gcp_create_project_2
    Create the project you want to use for your web app
    gcp_create_project_3
    Name and save your new project
  4. Select your new project

Step 2: Enable Google drive API​

  1. Enter in the "Enable APIS AND SERVICES" section

    gcp_enable_api_1
  2. Select "Google Drive API" and enable the API

  1. Navigate to the "APIs & Services" dashboard

    gcp_oauth_config_1
    From the dashboard, click on "Explore and enable APIs"
    gcp_oauth_config_2
    From the dashboard, click on "Click on "Credentials."
  2. Open the consent screen configuration

    gcp_oauth_config_3
    Click on "Configure consent screen"
  3. Select the appropriate User Type for your app

    gcp_oauth_config_4
    Create your consent screen
  4. Fill the consent screen configuration

    gcp_oauth_config_5
    Fill all the consent screen configuration
  5. Edit scopes

    gcp_oauth_config_6
    Click on "ADD OR REMOVE SCOPES"
  6. Add manually a new scope

    https://www.googleapis.com/auth/drive.appdata
    gcp_oauth_config_7
  7. Optionnaly, function of the User Type, add Test users.

Step 4: Set Up OAuth 2.0 Client IDs​

  1. Select Credentials

    gcp_oauth_credentials_1
    Click on "Create credentials" and select "OAuth client ID."
  2. Set the application type

    gcp_oauth_credentials_2
    Choose "Web application" as the application type.
  3. Fill in the required fields

    gcp_oauth_credentials_3
    Such as the "Name," "Authorized JavaScript origins," and "Authorized redirect URIs."
  4. Click "Create" to generate your OAuth 2.0 credentials

    gcp_oauth_credentials_4
    Save the generated "Client ID" and "Client Secret" for later use.

Next Steps​

Once you have created a wallet and added an account, you can perform various actions like checking the account balance, sending and receiving assets.