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:
Parameter | Type | Required | Description |
---|---|---|---|
String | Yes | The email address of the user to enroll. | |
firstName | String | Yes | The first name of the user. |
lastName | String | Yes | The last name of the user. |
role | String | Yes | The role assigned to the user (admin, user). |
serviceName | String | Yes | The name of the service for enrollment. |
Response Description
Upon successful enrollment, the enrollUser
method returns a response object containing the following attributes:
Key | Type | Description |
---|---|---|
id | String | A unique identifier for the user. |
firstName | String | The user's first name. |
lastName | String | The user's last name. |
username | String | The user's username. |
uuid | String | A universally unique identifier for the user. |
phone | String | The user's phone number. |
role | String | The user's role within the system. |
status | String | The user's account status. |
String | The user's email address. | |
chaincode | String | Associated chaincode identifier. |
channel | String | The blockchain channel the user is associated with. |
profilePic | String | URL to the user's profile picture. |
_id | String | Database identifier for the user. |
createdAt | String | Timestamp of user creation. |
updatedAt | String | Timestamp of the last user update. |
clientId | String | Identifier for the client application. |