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:

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

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

  • 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} owner - The address of the owner of the role.
* @param {string} roleId - The ID of the role whose permissions are to be fetched.
* @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(owner, roleId) {
const sdkInstance = await Sdk.createInstance({
baseUrl: "wss://wsspc1-qa.agung.peaq.network",
});

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

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

// Example usage
const ownerAddress = "5GsA2xjSBY6DhpTGKKdJ4BjUYpbBaP5wxZnvBoHSytURn6N2"; // Replace with actual owner address
const roleId = "78709009-cf06-4224-8632-b5ee8512"; // Replace with actual role ID

fetchRolePermissions(ownerAddress, roleId)
.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",
}
]