Skip to main content

fetchRolePermissions

The fetchRolePermissions function allows to retrieve permissions associated with a specific role from the network's Role-Based Access Control (RBAC) system. This function returns a JSON object with permission and role info.

Parameters:

  • roleId (Type: string, Required): ID of the role for which permissions are to be fetched.

  • owner (Type: address, Required): address of the owner of the role.

  • address (Type: address, Optional): address of the entity initiating the request. This parameter is optional.

  • seed (Type: string, Optional): The seed for transaction signing. This parameter is optional.

Code example


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

/**
* Fetches permissions associated with a specific role from the peaq network's RBAC system.
* @param {string} roleId - The ID of the role whose permissions are to be fetched.
* @param {string} owner - The address of the owner of the role.
* @param {string} [address] - The address of the entity initiating the request (optional).
* @param {string} [seed] - The seed for transaction signing (optional).
* @returns {Promise<Array<Object>>} - A promise that resolves to an array of objects containing permissions and role details.
*/
async function fetchRolePermissions(roleId, owner) {
const sdkInstance = await Sdk.createInstance({
baseUrl: "wss://wsspc1-qa.agung.peaq.network",
});

try {
const permissions = await sdkInstance.rbac.fetchRolePermissions({
roleId,
owner
});

return permissions;
} catch (error) {
console.error(`Error fetching role permissions: ${error}`);
return [];
} finally {
await sdkInstance.disconnect();
}
}

// Example usage
const roleId = "78709009-cf06-4224-8632-b5ee8512"; // Replace with actual role ID
const ownerAddress = "5GsA2xjSBY6DhpTGKKdJ4BjUYpbBaP5wxZnvBoHSytURn6N2"; // Replace with actual owner address
fetchRolePermissions(roleId, ownerAddress)
.then((permissions) => {
console.log("Fetched Role Permissions:", permissions);
})
.catch((error) => {
console.error("Error fetching role permissions:", error);
});


response object


[
{
permission: "18709409-bc06-4444-2222-b4zz0000",
role: "78709009-cf06-4224-8632-b5ee8512",
}
]