Skip to main content

updateRole

The updateRole function allows you to modify the name of a role in the network's Role-Based Access Control (RBAC) system. This function returns a JSON object with a role ID and a new name.

Parameters:

  • roleId (type: string, required): ID of the role you want to update.

  • name (type: string, required): a new name you want to assign to the role.

  • address (type: address, optional): address of the entity initiating the update.

  • seed (type: string, optional): seed used for transaction signing.

Code example


/**
* Updates a role's name in the peaq network's RBAC system.
*
* @param {string} roleId - The ID of the role to be updated.
* @param {string} name - The new name for 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<object>} - A promise that resolves when the role is successfully updated.
*/
const updateRole = async (roleId, name, seed) => {
// Connect to the peaq network's RBAC system using the provided parameters
const sdkInstance = await Sdk.createInstance({
baseUrl: "wss://wsspc1-qa.agung.peaq.network",
seed
});

try {
// Update the role's name with the provided new name
const result = await sdkInstance.rbac.updateRole({
roleId,
name,
});
return result
} finally {
// Disconnect from the network after the operation
await sdkInstance.disconnect();
}
};


const seed = "your-seed-phrase";
const roleId = "78709009-cf06-4224-8632-b5ee8512";
const updatedName = "newRoleName";

updateRole(roleId, updatedName, seed)
.then((result) => {
console.log(result.message);
})
.catch((error) => {
console.log("Error", error);
})

Response object


{
message: "Successfully update role 78709009-cf06-4224-8632-b5ee8512 with new name: newRoleName"
}