Skip to main content

updateGroup

updateGroup function is used to update the properties of an existing group in the RBAC system. This function returns a JSON object with a group ID and a new name.

Parameters:

  • name (required): updated name for the group.

  • groupId (required): ID of the group to be updated.

  • address (optional): address associated with the update.

  • seed (optional): mnemonic seed.

Code example


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

/**
* Update the properties of an existing group in the RBAC system.
* @param {string} name - The updated name for the group (required).
* @param {string} groupId - The ID of the group to be updated (required).
* @param {Address} [address] - The address associated with the update (not required).
* @param {string} [seed] - The mnemonic seed (not required).
* @returns {Promise<Object>} - A promise that resolves to an object containing the result of the update operation.
*/
const updateGroup = async (name, groupId, seed) => {
const sdkInstance = await Sdk.createInstance({
baseUrl: "wss://wsspc1-qa.agung.peaq.network",
seed,
});

try {
await sdkInstance.connect();
const result = await sdkInstance.rbac.updateGroup({
groupId: groupId,
name: name,
});

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

// Example usage
const updatedGroupName = "newGroupName";
const groupToUpdateId = "02709409-kd01-4444-8222-b5zz8512"; // Provide the actual group ID
const seed = "your-seed-phrase";

updateGroup(updatedGroupName, groupToUpdateId, seed)
.then((result) => {
console.log(result.message); // Print the result message
})
.catch((error) => {
console.error("Error updating group:", error);
});


Response object


{
message: "Successfully update group 02709409-kd01-4444-8222-b5zz8512 with new name: newGroupName"
}