Skip to main content

fetchPermissions

fetchPermissions function fetches all permission information from the Role-Based Access Control (RBAC) system on the PEAQ network. This function returns a JSON object with permissions info.

Parameters:

  • owner (required): address of the owner of the permissions for which you want to fetch details.

Code example

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

/**
* Fetches permission information from the Role-Based Access Control (RBAC) system.
* @param {Address} owner - The address of the owner of the permission (required).
* @returns {Promise<Array<Object>>} - A promise that resolves to an array of objects containing fetched permission details.
*/
const fetchPermission = async (owner) => {
const sdkInstance = await Sdk.createInstance({
baseUrl: "wss://wsspc1-qa.agung.peaq.network",
});

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

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

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

fetchPermission(ownerAddress)
.then((permissions) => {
if (permissions.length > 0) {
console.log("Fetched Permissions:", permissions);
} else {
console.log("No permissions found for the specified owner.");
}
})
.catch((error) => {
console.error("Error fetching permissions:", error);
});

Response object

[
{
"id": "18709409-bc06-4444-2222-b4zz0000",
"name": "myPermission",
"enable": true
}
]