Skip to main content

fetchRole

The fetchRole function allows to retrieve role information from a network's RBAC (Role-Based Access Control) system based on the provided parameters. This function returns a JSON object with role info.

Parameters:

  • owner (required): address of the owner of the role.
  • roleId (required): ID of the role to be fetched.

Code example


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

/**
* Fetches role information 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 to be fetched.
* @returns {Promise<Object>} - A promise that resolves to an object containing fetched role details.
*/

const fetchRole = async (owner, roleId) => {
const sdkInstance = await Sdk.createInstance({
baseUrl: "wss://wsspc1-qa.agung.peaq.network",
});

try {
const role = await sdkInstance.rbac.fetchRole({
owner,
roleId,
});

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

// Example usage
const ownerAddress = "5GsA2xjSBY6DhpTGKKdJ4BjUYpbBaP5wxZnvBoHSytURn6N2";
const roleId = "78709009-cf06-4224-8632-b5ee8512";

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


Response object


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