Create Wallet

Create personalized wallets for end users.

The sampleCreateWallet function is provided by the DICE ID SDK to demonstrate the process of creating a wallet for the end user.

It prompts the user to enter the wallet name and key, sets the wallet type to "indy", and calls the createWallet function from the diceidsdk.cloudwallet module.

API Elements:

  1. walletInput: An object that holds the wallet name, key, and type for creating the wallet.

  2. walletOutput: A variable that stores the response from the createWallet API.

  3. wallet_name: Stores the wallet name entered by the user.

  4. wallet_key: Stores the wallet key entered by the user.

  5. walletInput.wallet_name: Sets the wallet name in the walletInput object.

  6. walletInput.wallet_key: Sets the wallet key in the walletInput object.

  7. walletInput.wallet_type: Sets the wallet type as "indy" in the walletInput object.

  8. diceidsdk.cloudwallet.createWallet(): Creates a wallet using the walletInput object.

  9. resp: Holds the response from the createWallet API, including the wallet details.

  10. err: Stores any error that occurs during the process.

function sampleCreateWallet() {
  const walletInput = {};
  let walletOutput = {};
  // Prompt the user for wallet name and key
  const wallet_name = prompt('Enter Wallet name: ');
  const wallet_key = prompt('Enter Wallet key: ');
  // Set the wallet name, key, and type
  walletInput.wallet_name = wallet_name;
  walletInput.wallet_key = wallet_key;
  walletInput.wallet_type = "indy";
  // Call the createWallet function
  diceidsdk.cloudwallet.createWallet(walletInput)
    .then(resp => {
      walletOutput = resp;
      // Handle the wallet creation response
    })
    .catch(err => console.log("Not able to create wallet"));
}

Running the Code

Step 1: Add the sampleCreateWallet function: Copy the above sampleCreateWallet function code and paste it into your JavaScript file after importing the diceidsdk module.

Step 2: Run the function: Invoke the sampleCreateWallet function in your code to execute it. For example:

node sampleCreateWallet.js

Step 3: Provide input: The function will prompt you to enter the wallet name and key. Enter the required information in the terminal or command prompt.

Step 4: Handle the response: Once the createWallet function completes, you can handle the response within the .then() block of the promise or perform any necessary error handling in the .catch() block.

Step 5: The generated Wallet ID should copied into the "appconfig" file

Last updated