Skip to main content

Retrieving User

This guide details the process for retrieving the account ID (username) of a user within your blockchain application using the ERC1155 API's getAccount method. This functionality is crucial for managing user-specific operations, such as token transfers.


Overview of the getAccount Method

The getAccount method is used to fetch the account ID associated with a user's unique identifier (UUID). This operation is essential for applications that require user identification for transactions or account management.


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.
  • The UUID of the user for whom you wish to retrieve the account ID. This is typically obtained from the user enrollment process.

Sample Code Snippet

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

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

async function getAccount() {
// Configuration settings for the ERC1155 instance
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 retrieving the account ID
const dataToGetAccountId = {
userId: 'userUuid', // UUID of the user
chaincode: 'optionalChaincodeName', // Optional chaincode name
channel: 'optionalChannelName', // Optional blockchain channel
};

try {
// Perform the operation to fetch the account ID
const accountIdResponse = await erc1155.getAccount(dataToGetAccountId);
// Handle success
} catch (error) {
// Handle error
}
}

Request Parameters

ParameterTypeRequiredDescription
userIdStringYesThe UUID of the user for whom to retrieve the account ID.
chaincodeStringNoThe name of the smart contract or chaincode managing the tokens.
channelStringNoThe name of the blockchain channel where the operation occurs.

Response Format

Upon successful retrieval, the getAccount method returns a response object containing the following attribute:

KeyTypeDescription
usernameStringThe account ID (username) of the user.