Skip to main content

fetchPermission

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

Parameters:

  • permissionId (Type string, Required): ID of the permission to be fetched. This parameter is required.

  • owner (Type Address, Required): address of the owner of the permission. This parameter is required.

Code example


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

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

try {
await sdkInstance.connect();
const permission = await sdkInstance.rbac.fetchPermission({
permissionId: permissionId,
owner: owner,
});

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

// Example usage
const permissionId = '18709409-bc06-4444-2222-b4zz0000';
const ownerAddress = '5GsA2xjSBY6DhpTGKKdJ4BjUYpbBaP5wxZnvBoHSytURn6N2';
const seed = "your-seed-phrase";

fetchPermission(permissionId, ownerAddress, seed)
.then((permission) => {
console.log("Fetched Permission:", permission);
})
.catch((error) => {
console.error("Error fetching permission:", error);
});


Response object


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