Skip to main content

Account Id of User

Retrieving the account ID of a user is a key functionality in the edeXa ERC20 API. Use the accountId method to obtain this information.


Prerequisites

  • Authenticate the client using the edeXa SDK. For authentication details, see the authentication method.
  • Ensure that the user whose account ID you want to retrieve is already enrolled. See enroll users for details on enrolling users.

Sample code Snippet

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

// SDK.js
import { ERC20, Network } from 'edeXa-sdk';

async function accountId() {
const erc20 = new ERC20({
...settings,
authorization: `Bearer ${token}`,
});

const settings = {
network: Network.SANDBOX, // or Network.MAINNET for the mainnet network
};

const dataToGetAccountId = {
userId: 'Enter the uuid of the user',
chaincode: 'Name of the smart contract', // Optional
channel: 'Name of the channel', // Optional
};

try {
const accountIdResponse = await erc20.accountId(dataToGetAccountId);
// Handle success
} catch (error) {
// Handle error
}
}

Important Notes

  • Authentication Token: Replace the token in the authorization header with your actual authentication token.
  • Asynchronous Execution: The accountId function is an async function that uses await to wait for the erc20.accountId method's promise to resolve.
  • User UUID: Provide the uuid of the user in the userId field. This uuid can be obtained from the response of enroll users.

Request Parameters

The dataToGetAccountId object requires the following parameters:

ParameterRequiredTypeDescriptionDefault
userIdYesStringThe uuid of the user for whom to retrieve the account ID
chaincodeOptionalStringThe name of the smart contract managing the tokensDefault chaincode
channelOptionalStringThe name of the channel in the blockchain networkDefault channel

Response Format

The response from the accountId method includes:

KeyTypeDescription
usernameStringThe username (account ID) of the user