Create Sub Account Wallets

Introduction

Sub account wallet is everything the cryptocurrency wallets created in the previous section are, but with a little twist. While wallets are specific to users, sub-accounts provides a new revolutionary way of managing wallets on your platform, by creating wallets as subsidiary accounts of a central wallet; this will be discussed in more details in the subsequent sections.

Sub Accounts

Sub accounts is a feature that makes provisions for subsidiary wallets to be created but pegged to a defined main account. With this architecture, all funds are stored in the central account (otherwise called main account), rather than generating separate wallets for users and storing crypto in a diversified pattern. This makes it easier to keep track of balances, and manage incomings and outgoings on your system.

The sub accounts created for each user can then contain references which would be used to keep them updated as to the user balances, and their transaction history. While the user's still have wallet addresses, upon deposits, the fund is routed to the main account, and transaction logs are made to ensure the user account is updated too.

Steps to Creating Sub Accounts

When creating sub accounts, the most important properties are the symbols, networks and owner. The owner object contains fields such as the name and email fields. The email property can serve as your key/unique identifier for your users, as no two users can have the same email addresses. Using this, you can determine if a user already has a sub account, and create additional wallets within the same sub account for the user. There is also a metadata field that takes in an array of objects, and let's you define custom key-value pairs to add as you see fit, offering flexibility. You can decide to change your method to feature another property for your key if you so desire. To create sub accounts, you can choose to get user details via input on your platform, and store it in the following format:

 const data = {
  symbols: ["ETH", "TRX", "SOL"],
  networks: ["bsc"],
  owner: {
    name: "John Doe",
    email: "[email protected]",
    phone: `${dial_code}${userEnteredPhone}`,
  },
  metadata: metadata,
};

The metadata field can be used to store additional information about the addresses, userID, etc. This can be useful for KYC purposes, and for keeping track of user information. The table below shows the properties that can be used to create sub accounts:

PropertyDescriptionTypeRequired
symbolsThe cryptocurrency symbolArrayYes
networksThe blockchain networkArrayYes
ownerThe owner of the sub accountObjectYes
metadataAdditional informationArrayNo

To create a sub account, follow the steps outlined below:

  • Step 1: Get the user details using your preferred method (e.g input fields).
  • Step 2: Store the user details in the format shown above.
  • Step 3: Make a POST request as shown in the code snippet below (Note that otherwise stated, code blocks are in TypeScript):
...
fetch("https://api.100pay.co/api/v1/assets/subaccount/create", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "api-key": pub_keys[0].value as string,
  },
  body: JSON.stringify(data),
  })
  .then((res) => res.json())
  .then((data) => {
   // Handle response
  }),

In the code snippet above, the pub_keys[0].value is the your public API key which can be gotten from your 100Pay dashboard. The data object contains the user details in the format shown above. The response from the API call will contain the sub account details created for the user.

Conclusion

With this, you can create sub accounts for your users, and manage their wallets in a more organized manner. This feature is particularly useful for platforms that require a more organized way of managing user wallets, and keeping track of their balances and transaction history. The next section will discuss how to manage user balances and transaction history.