Query Circles Data
The CirclesData class provides an easy-to-use selection of common queries that are suitable for most use cases.
Initialization
Most of the previously shown avatar methods internally use the CirclesData
class with filters for the current avatar address. If you already have a configured Sdk
instance, you can use the sdk.data
property to access the class:
Otherwise you can create an instance like this:
Get avatar info
The getAvatarInfo(avatar: string): Promise<AvatarRow | undefined>
method finds basic information about an avatar. This includes the signup timestamp, circles version, avatar type (human, organization or group), and token address/id as well as it's profile CID (if any).
This method is useful to check if an avatar exists before using .
Get token info
The getTokenInfo(tokenId: string): Promise<TokenInfoRow | undefined>
methods finds basic information about a Circles token. This includes the creation timestamp, circles version, token type (human or group) and the address of the avatar that created the token.
Get total balance (v1, v2)
The total Circles balance of an avatar is the sum of all it's personalized and group token holdings. It can be queried with the getTotalBalance(avatar:string): Promise<string>
method. There is a separate method for each Circles version.
The methods have a second, optional parameter asTimeCircles?: boolean = true
that controls the return value format. The default value (true
) returns a floating point number
as a string, while false
returns a bigint
number as a string. If you want to use the value for calculations you need to parse them.
Get detailed token balances (v1, v2)
In contrast to the above method, the getTokenBalances(avatar: string): Promise<TokenBalanceRow[]>
method gives a detailed overview of an avatar's Circles holdings. As with the method above, this one also exists for both versions of the Circles protocol.
The result row contains the token
, balance
and the tokenOwner
.
The methods have a second, optional parameter asTimeCircles?: boolean = true
that controls the return value format. The default value (true
) returns a floating point number
as a string, while false
returns a bigint
number as a string. If you want to use the value for calculations you need to parse them.
Get transaction history
The getTransactionHistory(avatar: string, pageSize: number): CirclesQuery<TransactionHistoryRow>
method can be used to query all incoming and outgoing Circles transfers from and to an avatar. This includes minting and transfers of personal and group Circles for v1 and v2.
The result rows have the following properties:
timestamp
When the transaction happenedtransactionHash
version
If the transaction happened in Circles v1 or v2operator
(the operator that facilitated the transaction - v2 only)from
the sender addressto
the receiver addressid
in v1: the token address, in v2: the token idvalue
the transferred raw value for the given version (bigint)timeCircles
a floating point number representation of thevalue
for display purposestokenAddress
an address representation of the numeric tokenid (v2) or the actual erc20 token address of a v1 personal token
The results are ordered in descending order.
Get trust relations
The getTrustRelations(avatar: string, pageSize: number): CirclesQuery<TrustListRow>
method can be used to query the effective trust events for an avatar. Already expired or removed trust relations are omitted from the results.
The results of this method contain one row per incoming or outgoing event. This is useful when you need to know when a relation was established. However, if you just want to display a contact list you should consider using getAggregatedTrustRelations(avatarAddress: string): Promise<TrustRelationRow[]>
instead.
Get aggregated trust relations
In contrast to the above method, this method queries all relevant trust events and groups mutual trust events into a single row instead of one for each direction.
The result rows have the following properties:
subjectAvatar
The acting avatarrelation
The relation between the acting avatar and the one it's related toobjectAvatar
The other avatar
The possible relations are: trusts
, trustedBy
, mutuallyTrusts
, and selfTrusts
. The last one (selfTrusts
) exists because, in Circles, every avatar trusts itself.
Find groups
Circles groups have a name and symbol that's stored on-chain. You can use the findGroups(pageSize: number, params: GroupQueryParams): CirclesQuery<GroupRow>
method to find groups by name or symbol.
The params
parameter can be used to filter and order the result set by the name
and symbol
of a group.
Use the method as following:
If an avatar is member at a group (as defined by a trust relation from the group to the avatar), it's usually eligible to mint tokens of that group.
Get group memberships
You can query the group memberships of an avatar using the getGroupMemberships(avatar: string, pageSize: number): CirclesQuery<GroupMembershipRow>
method to get a list of all groups an avatar is a member of.
The result rows contain the following properties: group
, member
, expiryTime
.
If you want to query the details of the returned groups, you can pass the group addresses into the groupAddressIn
filter field of the findGroups()
method.
Get invited users
Avatars can invite others to join Circles. The getInvitations(avatar: string, pageSize: number): CirclesQuery<InvitationRow>
method returns a list of invitations sent by the specified avatar.
Th e result rows contain the follwing properties: timestamp
, transactionHash
, inviter
, invited
.
Get invited by
You can query who invited an other avatar by calling getInvitedBy(avatar:string): Promise<string|undefined>
. If the avatar wasn't invited, the method returns undefined.
Last updated