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 theauthorization
header with your actual authentication token. - Asynchronous Execution: The
accountId
function is anasync
function that usesawait
to wait for theerc20.accountId
method's promise to resolve. - User UUID: Provide the
uuid
of the user in theuserId
field. Thisuuid
can be obtained from the response of enroll users.
Request Parameters
The dataToGetAccountId
object requires the following parameters:
Parameter | Required | Type | Description | Default |
---|---|---|---|---|
userId | Yes | String | The uuid of the user for whom to retrieve the account ID | |
chaincode | Optional | String | The name of the smart contract managing the tokens | Default chaincode |
channel | Optional | String | The name of the channel in the blockchain network | Default channel |
Response Format
The response from the accountId
method includes:
Key | Type | Description |
---|---|---|
username | String | The username (account ID) of the user |