πŸ“Avatar information

Avatars provide easy to use methods to query common values like trust lists and balances.

Avatar info

The avatarInfo property contains the most important properties of your avatar like it's address, type, tokenId and version.

const avatar = await sdk.getAvatar(avatarAddress);
console.log(avatar.avatarInfo);

Organization avatars don't have a tokenId.

Total balance

This method returns the total Circles balance of an avatar as number.

const totalBalance = await avatar.getTotalBalance();

Mintable amount

Human avatars can mint 24 personal Circles per day. You can call getMintableAmount() to check how much Circles can be minted right now.

const mintableAmount = await avatar.getMintableAmount();

Trust relations

Trust relations play a critical role in Circles. A core principle is, that avatars only accept Circles that they previously trusted. Trust relations and their effects will be explained in greater detail at a later point. For now, you can think of it as a contact list.

const trustRelations = await avatar.getTrustRelations();

The method returns an array of TrustRelationRows, each with subjectAvatar, relation and objectAvatar attributes. That can be read as:

  • 0x111... trusts 0x222...

where the first address is the subject, 'trusts' specifies the relation and the last address is the object. The following relations exist: trusts, trustedBy, mutuallyTrusts.

Transaction history

Circles transfers, personal and group minting transactions will show up in the avatar's transaction history. You can call getTransactionHistory(pageSize) to get a paginated transaction history list.

const transactionHistory = await avatar.getTransactionHistory(25);

The function returns a CirclesQuery<T> object that must be 'unrolled' by calling queryNextPage() to get the data. You're going to see more of this later when we use the @circles-sdk/data package directly.

const transactionHistoryQuery = await avatar.getTransactionHistory(25);
const hasData = await transactionHistoryQuery.queryNextPage();
if (hasData) {
    console.log(transactionHistoryQuery.currentPage?.results);
}

The result rows contain from, to and value properties as well as (in some cases) the tokenAddress of the transferred token. The currentPage, additionally to the results, has the following fields: limit, size, firstCursor, lastCursor, sortOrder. You can use these fields e.g. to implement infinite scrolling in your application.

The CirclesQuery class is not suitable for classic pagination at the moment because there is no way to get the total result count.

Next steps

On the next page we'll show how you can trust other avatars, mint personal Circles and transfer them.

Following that, you'll learn how to subscribe to events and how to query the other data that's available from the Circles RPC endpoint.

Full example

For a complete example that queries the balance, mintable amount, trust relations and transaction history, check out the Circles SDK Svelte Examples on GitHub. Specifically the Avatar information route.

Last updated