Circles Documentation
  • Welcome to Circles
  • Overview
    • Understanding Personal and Group Currencies
      • Personal Currencies
      • Group Currencies
    • Why Build on Circles?
    • Circles Architecture
  • Developer Docs
    • The Circles Stack
    • Circles SDK Overview
    • Quickstart Guide for Circles SDK
    • Setting Circles Profiles
    • Building with different Circles Avatars
      • Personal / Human Avatars
        • Inviting and accepting human avatars
        • Mint personal tokens
        • Fetching profile of an human avatar
        • Manage trust connections
        • Get token balances of an avatar
        • Transfer personal Circles tokens to different avatar
      • Group Avatars
        • Create Base Groups for your community.
          • Vanilla groups with V2 hub
        • Mint group tokens
        • Managing group invites
        • Find groups and memberships
        • Getting total supply of group tokens available
      • Organization Avatars
        • Creation of Organizations
        • Managing trust connections via Org avatar account
  • Tutorials and Examples
    • Setting up Circles SDK with React
  • Querying Circles profiles and data
    • Query Circles Data
    • Subscribing to Avatar events
    • Utilising CirclesQuery Class
    • Query Circles profiles
  • Circles SDK Reference
    • Circles SDK interface
    • SDK Methods
    • Circles Data Methods
    • Circles Events Types
  • Developer Support
    • Glossary
    • Past Hackathon Projects on Circles
Powered by GitBook
On this page
  • Find Groups
  • Get group memberships

Was this helpful?

Export as PDF
  1. Developer Docs
  2. Building with different Circles Avatars
  3. Group Avatars

Find groups and memberships

You would be requiring to initialize the Circles data property to find groups and get memberships.

const data = sdk.data

Otherwise you can create an instance like this:

const circlesRpc = new CirclesRpc("https://rpc.aboutcircles.com");
//or add RINGS rpc if you are building with RINGS

const data = new CirclesData(circlesRpc);

Find Groups

  • Functionality: This method allows you to fetch a list of groups from the Circles system, with options for pagination and filtering. This is useful for applications that need to display groups or for querying specific groups based on certain criteria.

  • Parameters:

    • pageSize: A number specifying how many groups should be returned in the response.

    • params: An optional parameter that can include various filters for the query, such as group types or statuses.

const groupsPageSize = 10; // Define the maximum number of groups to return
const queryParams = { /* Example filter parameters */ };

try {
    const groupsQueryResult = await circles.data.findGroups(groupsPageSize, queryParams);
    console.log('Retrieved groups:', groupsQueryResult);
} catch (error) {
    console.error('Error fetching groups:', error);
}

Get group memberships

This method is designed to fetch all group memberships associated with a specific avatar. This is useful for applications that want to display or manage the groups that a user belongs to.

Parameters:

  • avatar: A string representing the address of the avatar for which group memberships are being requested.

  • pageSize: A number that specifies the maximum number of group memberships to return.

const avatarAddress = '0xYourAvatarAddress'; 
// The address of the avatar
const membershipsPageSize = 5; 
// Define the maximum number of memberships to return

try {
    const membershipsQueryResult = await circles.getGroupMemberships(avatarAddress, membershipsPageSize);
    console.log('Retrieved group memberships:', membershipsQueryResult);
} catch (error) {
    console.error('Error fetching group memberships:', error);
}

Example Usage

Here's how you might use these methods in your code:

// Initialize the SDK  
const sdk = new Sdk(contractRunner, config);  
  
// Find all groups with names starting with "Community"  
const groupsQuery = sdk.data.findGroups(10, {  
  nameStartsWith: "Community"  
});  
  
// Fetch the first page of results  
await groupsQuery.queryNextPage();  
console.log("Found groups:", groupsQuery.currentPage?.results);  
  
// Find all groups that a specific avatar is a member of  
const avatarAddress = "0x123..."; // Replace with actual address  
const membershipsQuery = sdk.data.getGroupMemberships(avatarAddress, 10);  
  
// Fetch the first page of results  
await membershipsQuery.queryNextPage();  
console.log("Group memberships:", membershipsQuery.currentPage?.results);
PreviousManaging group invitesNextGetting total supply of group tokens available

Last updated 14 hours ago

Was this helpful?