Skip to main content

Enrolling Users

This guide outlines the steps to enroll users in your application using the ERC1155 API, a critical process for managing user access and permissions within your blockchain application.


Overview of the enrollUser Method

User enrollment is a foundational operation that allows you to register users in your system, assigning them specific roles and permissions. The enrollUser method facilitates this process within the ERC1155 standard, ensuring users are correctly set up to interact with your application.


Prerequisites

  • Installed the edeXa-sdk in your project.
  • An authentication token obtained through the SDK's authentication method. This token is necessary to authorize your requests.

Sample Code Snippet

Here is a JavaScript code snippet demonstrating the use of the enrollUser method:

import { ERC1155, Network } from 'edeXa-sdk';

async function enrollUser() {
const settings = {
network: Network.SANDBOX, // Use Network.MAINNET for production environments
};

const erc1155 = new ERC1155({
...settings,
authorization: `Bearer ${token}`, // Replace `${token}` with your actual token
});

// Data required for user enrollment
const dataToEnrollUser = {
email: 'user@example.com', // User's email
firstName: 'John', // User's first name
lastName: 'Doe', // User's last name
phone: '1234567890', // User's phone number
role: 'user', // User's role (e.g., admin, user)
countryCode: 'US', // User's country code
serviceName: 'erc1155', // Service name for enrollment
};

try {
const enrollUserResponse = await erc1155.enrollUser(dataToEnrollUser);
// Handle success
} catch (error) {
// Handle error
}
}

Required Parameters for Enrollment

The table below details the parameters you need to provide for enrolling a user:

ParameterTypeRequiredDescription
emailStringYesThe email address of the user to enroll.
firstNameStringYesThe first name of the user.
lastNameStringYesThe last name of the user.
roleStringYesThe role assigned to the user (admin, user).
serviceNameStringYesThe name of the service for enrollment.

Response Description

Upon successful enrollment, the enrollUser method returns a response object containing the following attributes:

KeyTypeDescription
idStringA unique identifier for the user.
firstNameStringThe user's first name.
lastNameStringThe user's last name.
usernameStringThe user's username.
uuidStringA universally unique identifier for the user.
phoneStringThe user's phone number.
roleStringThe user's role within the system.
statusStringThe user's account status.
emailStringThe user's email address.
chaincodeStringAssociated chaincode identifier.
channelStringThe blockchain channel the user is associated with.
profilePicStringURL to the user's profile picture.
_idStringDatabase identifier for the user.
createdAtStringTimestamp of user creation.
updatedAtStringTimestamp of the last user update.
clientIdStringIdentifier for the client application.