Skip to main content

createNewGroup

The createNewGroup function is used to create a new group within the RBAC (Role-Based Access Control) system. This function returns a JSON object with groupID.

Parameters:

  • groupName (required): name of the group to be created.

  • groupId (not required): ID of the group. If not provided, a new ID will be generated.

  • address (not required): address associated with the operation.

  • seed (not required): mnemonic seed used for transaction signing.

Code example


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

/**
* Create a new group within the RBAC system.
* @param {string} groupName - The name of the group to be created (required).
* @param {string} [groupId] - The ID of the group (not required).
* @param {Address} [address] - The address associated with the operation (not required).
* @param {string} [seed] - The mnemonic seed (not required).
* @returns {Promise<Object>} A promise that resolves to an object containing the groupId field.
*/
const addGroup = async (groupName, seed) => {
const sdkInstance = await Sdk.createInstance({
baseUrl: "wss://wsspc1-qa.agung.peaq.network",
seed,
});

try {
await sdkInstance.connect();
const groupId = await sdkInstance.rbac.createNewGroup({
groupName: groupName
});

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

// Example usage
const groupName = 'myGroup';
// Fund personal wallet to perform write operations
const seed = "your-seed-phrase";
addGroup(groupName, mnemonicSeed)
.then((groupId) => {
console.log(`Created group Id: ${groupId}`);
})
.catch((error) => {
console.error(`Error creating new group: ${error}`);
});


Response object


{
groupId: "02709409-kd01-4444-8222-b5zz8512"
}