Skip to main content

2. Instantiate Wallets and Accounts


This section of the documentation provides a detailed guide on creating Wallets and accounts using the Eniblock SDK. It covers the instantiation of a wallet, creating multiple accounts within a wallet, and listing all accounts in a wallet.


Instantiating a Wallet

To instantiate a new wallet:

  1. Import Eniblock and UnsafeStorage: Start by importing the required modules from the Eniblock SDK.
  2. Initialize the SDK: Create an instance of the Eniblock class, providing necessary parameters like appId, accessTokenProvider, and storage.
  3. Instantiate or Retrieve a Wallet: Use the sdk.wallet.instantiate() method to either create a new wallet or retrieve an existing one.
  4. Create an Account: Instantiate an account within the wallet using wallet.account.instantiate("Account Alias"), where "Account Alias" is a customizable name for the account.
  5. Display Account Details: Use various account methods like getAddress(), getNativeBalance(), etc., to display account information.

Example Code


Instantiating a Second Account

To add a second account:

  • Follow the same steps as above, but use a different alias for the second account.

Example Code for Second Account


List Wallet Accounts

To list all accounts in a wallet:

  1. Retrieve Wallet: Use sdk.wallet.instantiate() to retrieve the wallet instance.
  2. List Accounts: Use wallet.account.list() to get all accounts.
  3. Display Account Details: Iterate through each account, displaying details like address, balance, public key, and creation date.

Example Code for Listing Accounts


API References

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

Next Steps

  • Importance of Wallet Storage

    When you instantiate a wallet, it is crucial to store it up to avoid losing access to your funds. Storing the wallet keys client share in a secure and reliable location is essential to prevent unauthorized access and ensure you can recover your wallet if needed. To learn how to correctly store and retrieve a wallet, please follow the step-by-step tutorial: Store and retrieve a Wallet.

  • Explore further actions like checking account balances and transferring assets.