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, seed) => {
const sdkInstance = await Sdk.createInstance({
baseUrl: "wss://wss-async.agung.peaq.network",
seed,
});
try {
await sdkInstance.connect();
const groups = await sdkInstance.rbac.fetchGroups({
owner: owner
});
return groups;
} finally {
await sdkInstance.disconnect();
}
};
// Example usage
const ownerAddress = "5GsA2xjSBY6DhpTGKKdJ4BjUYpbBaP5wxZnvBoHSytURn6N2";
const seed = "your-seed-phrase";
fetchGroups(ownerAddress, seed)
.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
}
]