Skip to main content

fetchGroups

fetchGroups function returns an array with details about groups associated with the specified owner.

Parameters:

  • owner (Address): address of the owner for whom you want to fetch groups. This parameter is required.

Code example


import { Sdk } from "@peaq-network/sdk";

/**
* Fetches groups associated with a specific owner from the RBAC system.
* @param {string} owner - The address of the owner for whom to fetch groups (required).
* @returns {Promise<Array<Object>>} - A promise that resolves to an array of objects containing fetched group details.
*/
const fetchGroups = async (owner) => {
const sdkInstance = await Sdk.createInstance({
baseUrl: "wss://wsspc1-qa.agung.peaq.network",
});

try {
const groups = await sdkInstance.rbac.fetchGroups({
owner,
});

return groups;
} finally {
await sdkInstance.disconnect();
}
};

// Example usage
const ownerAddress = "5GsA2xjSBY6DhpTGKKdJ4BjUYpbBaP5wxZnvBoHSytURn6N2";

fetchGroups(ownerAddress)
.then((groups) => {
console.log("Fetched Groups:", groups);
})
.catch((error) => {
console.error("Error fetching groups:", error);
});


Response object

[
{
"id": "02709409-kd01-4444-8222-b5zz8512",
"name": "myGroup",
"enable": true
}
]