Skip to main content

Retrieving Total Tokens Owned by a User

Understanding the ownership distribution of tokens is vital for managing Non-Fungible Tokens (NFTs). The getOwnerDetails method provided by the edeXa ERC721 SDK allows querying the total tokens owned by a specific user. This document guides you through utilizing this method effectively.


Overview of the getOwnerDetails Method

The getOwnerDetails method fetches comprehensive details about the tokens owned by a user, including the Token URI, owner's username, and token ID. This information is crucial for applications that need to display or manage user-owned NFTs.


Prerequisites

  • Installation of the edeXa ERC721 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 getOwnerDetails method:

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

async function getOwnerDetails() {
const settings = {
network: Network.SANDBOX, // or Network.MAINNET for broader applications
authorization: `Bearer ${token}`, // Replace `${token}` with your actual authentication token
};

const erc721 = new ERC721(settings);
const dataToGetOwnerDetails = {
userId: 'Enter the username of the user', // Optional: Specify to retrieve tokens for a specific user
};

try {
const getOwnerDetailsResponse = await erc721.getOwnerDetails(
dataToGetOwnerDetails
);
// Handle success
} catch (error) {
// Handle error
}
}

Request Parameters

ParameterRequiredTypeDescription
userIdNoStringThe username of the user to retrieve the total tokens owned by them.

Response Format

Upon successful request execution, the response includes an array of objects, each representing a token owned by the user.

AttributeTypeDescription
tokenUriStringThe URI associated with the token's metadata.
ownerStringThe username of the token owner.
tokenIdNumberThe unique identifier of the token.