import{Sdk}from"@peaq-network/sdk";constHTTPS_BASE_URL="https://peaq.api.onfinality.io/public";constEVM_PRIVATE= process.env["EVM_PRIVATE"];const sdk =awaitSdk.createInstance({baseUrl:HTTPS_BASE_URL,chainType:Sdk.ChainType.EVM});const groupName ="peaq-group-1";const group =await sdk.rbac.createGroup({groupName: groupName});// Send using Sdk functionconst receipt =awaitSdk.sendEvmTx({tx: group.tx,baseUrl:HTTPS_BASE_URL,seed:EVM_PRIVATE});// Log to see what the auto generated groupId isconsole.log(group.groupId);
For the EVM tx it returns in a different form than what was used throughout the sdk. The purpose of this is to show the group-id that was autogenerated if it was not manually set.
That way you are able to take note of the group-id for that group-name set.
import{Sdk}from"@peaq-network/sdk";constHTTPS_BASE_URL="https://peaq.api.onfinality.io/public";constWSS_BASE_URL="wss://peaq.api.onfinality.io/public";constEVM_ADDRESS= process.env["EVM_ADDRESS"];const sdk =awaitSdk.createInstance({baseUrl:HTTPS_BASE_URL,chainType:Sdk.ChainType.EVM});// example of a previously created group idconst groupId ="58a52684-3ace-4e72-a025-85085b1d";const response =await sdk.rbac.fetchGroup({owner:EVM_ADDRESS,groupId: groupId,wssBaseUrl:WSS_BASE_URL});
import{Sdk}from"@peaq-network/sdk";constHTTPS_BASE_URL="https://peaq.api.onfinality.io/public";constWSS_BASE_URL="wss://peaq.api.onfinality.io/public";constEVM_ADDRESS= process.env["EVM_ADDRESS"];constEVM_PRIVATE= process.env["EVM_PRIVATE"];const sdk =awaitSdk.createInstance({baseUrl:HTTPS_BASE_URL,chainType:Sdk.ChainType.EVM});// new group name that will be setconst groupName ="peaq-group-new";// example of a previously created group idconst groupId ="58a52684-3ace-4e72-a025-85085b1d";// build the evm txconst tx =await sdk.rbac.updateGroup({groupName: groupName,groupId: groupId});// send using Sdk functionconst receipt =awaitSdk.sendEvmTx({tx: tx,baseUrl:HTTPS_BASE_URL,seed:EVM_PRIVATE});// fetch Group to confirm the name changeconst response =await sdk.rbac.fetchGroup({owner:EVM_ADDRESS,groupId: groupId,wssBaseUrl:WSS_BASE_URL});
import{Sdk}from"@peaq-network/sdk";constHTTPS_BASE_URL="https://peaq.api.onfinality.io/public";constWSS_BASE_URL="wss://peaq.api.onfinality.io/public";constEVM_ADDRESS= process.env["EVM_ADDRESS"];constEVM_PRIVATE= process.env["EVM_PRIVATE"];const sdk =awaitSdk.createInstance({baseUrl:HTTPS_BASE_URL,chainType:Sdk.ChainType.EVM});// group id to disableconst groupId ="58a52684-3ace-4e72-a025-85085b1d";// build the evm txconst tx =await sdk.rbac.disableGroup({groupId: groupId});// send using Sdk functionconst receipt =awaitSdk.sendEvmTx({tx: tx,baseUrl:HTTPS_BASE_URL,seed:EVM_PRIVATE});// fetch group to confirm it has been changed to disabledconst response =await sdk.rbac.fetchGroup({owner:EVM_ADDRESS,groupId: groupId,wssBaseUrl:WSS_BASE_URL});
import{Sdk}from"@peaq-network/sdk";constHTTPS_BASE_URL="https://peaq.api.onfinality.io/public";constEVM_PRIVATE= process.env["EVM_PRIVATE"];const sdk =awaitSdk.createInstance({baseUrl:HTTPS_BASE_URL,chainType:Sdk.ChainType.EVM});// group id (generated with createGroup)const groupId ="58a52684-3ace-4e72-a025-85085b1d";// role id to assign to groupconst roleId ="ada650fa-ec62-4d09-849b-b66c7777";// build the evm txconst tx =await sdk.rbac.assignRoleToGroup({groupId: groupId,roleId: roleId});// send using Sdk functionconst receipt =awaitSdk.sendEvmTx({tx: tx,baseUrl:HTTPS_BASE_URL,seed:EVM_PRIVATE});
import{Sdk}from"@peaq-network/sdk";constHTTPS_BASE_URL="https://peaq.api.onfinality.io/public";constWSS_BASE_URL="wss://peaq.api.onfinality.io/public";constEVM_ADDRESS= process.env["EVM_ADDRESS"];constEVM_PRIVATE= process.env["EVM_PRIVATE"];const sdk =awaitSdk.createInstance({baseUrl:HTTPS_BASE_URL,chainType:Sdk.ChainType.EVM});// previously created groupIdconst groupId ="58a52684-3ace-4e72-a025-85085b1d";// role id to unassign to groupconst roleId ="b68a5589-1284-49e9-8276-0359a429";// build the evm txconst tx =await sdk.rbac.unassignRoleToGroup({groupId: groupId,roleId: roleId});// send using Sdk functionconst receipt =awaitSdk.sendEvmTx({tx: tx,baseUrl:HTTPS_BASE_URL,seed:EVM_PRIVATE});// fetch to see it has been unassignedconst response =await sdk.rbac.fetchGroupRoles({owner:EVM_ADDRESS,groupId: groupId,wssBaseUrl:WSS_BASE_URL});
import{Sdk}from"@peaq-network/sdk";constHTTPS_BASE_URL="https://peaq.api.onfinality.io/public";constEVM_PRIVATE= process.env["EVM_PRIVATE"];const sdk =awaitSdk.createInstance({baseUrl:HTTPS_BASE_URL,chainType:Sdk.ChainType.EVM});// user id to assign to groupconst userId ="9e8c7866-8435-4b76-8683-709a03c9";// group id (generated with createGroup)const groupId ="58a52684-3ace-4e72-a025-85085b1d";// build the evm txconst tx =await sdk.rbac.assignUserToGroup({userId: userId,groupId: groupId,});// send using Sdk functionconst receipt =awaitSdk.sendEvmTx({tx: tx,baseUrl:HTTPS_BASE_URL,seed:EVM_PRIVATE});
import{Sdk}from"@peaq-network/sdk";constHTTPS_BASE_URL="https://peaq.api.onfinality.io/public";constWSS_BASE_URL="wss://peaq.api.onfinality.io/public";constEVM_ADDRESS= process.env["EVM_ADDRESS"];constEVM_PRIVATE= process.env["EVM_PRIVATE"];const sdk =awaitSdk.createInstance({baseUrl:HTTPS_BASE_URL,chainType:Sdk.ChainType.EVM});// user id to unassign from groupconst userId ="9e8c7866-8435-4b76-8683-709a03c9";// previously created groupIdconst groupId ="58a52684-3ace-4e72-a025-85085b1d";// build the evm txconst tx =await sdk.rbac.unassignUserToGroup({userId: userId,groupId: groupId,});// send using Sdk functionconst receipt =awaitSdk.sendEvmTx({tx: tx,baseUrl:HTTPS_BASE_URL,seed:EVM_PRIVATE});// fetch to see it has been unassignedconst response =await sdk.rbac.fetchUserGroups({owner:EVM_ADDRESS,userId: userId,wssBaseUrl:WSS_BASE_URL});