Skip to main content

fetchRoles

The fetchRoles function fetches the roles associated with a user (owner) from the network's RBAC system. It takes the owner as a required parameter. It returns an array of role objects.

Parameters:

  • ownerAddress (required): address representing the owner of the role.

Code example


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

/**
* Fetches role information from the peaq network's RBAC system.
* @param {string} ownerAddress - The address of the owner of the role.
* @returns {Promise<Array<object>>} - A promise that resolves to an array of object containing fetched role details.
*/
const fetchRole = async (ownerAddress) => {
const sdkInstance = await Sdk.createInstance({
baseUrl: "wss://wsspc1-qa.agung.peaq.network",
});

try {
const roles = await sdkInstance.rbac.fetchRoles({
ownerAddress
});

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

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

fetchRole(ownerAddress)
.then((roles) => {
console.log("Fetched Roles:", roles);
})
.catch((error) => {
console.error("Error fetching roles:", error);
});

Response object


[
{
"id": "78709009-cf06-4224-8632-b5ee8512",
"name": "myRole",
"enable": true
}
]