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 roleName ="peaq-role-1";const role =await sdk.rbac.createRole({roleName: roleName});// Send using Sdk functionconst receipt =awaitSdk.sendEvmTx({tx: role.tx,baseUrl:HTTPS_BASE_URL,seed:EVM_PRIVATE});// Log to see what the auto generated roleId isconsole.log(role.roleId);
The EVM tx it returns in a different form than what was used throughout the sdk. The purpose of this is to show the role-id that was autogenerated if it was not manually 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 role idconst roleId ="b68a5589-1284-49e9-8276-0359a429";const response =await sdk.rbac.fetchRole({owner:EVM_ADDRESS,roleId: roleId,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 role name that will be setconst roleName ="peaq-role-new";// example of a previously created role idconst roleId ="b68a5589-1284-49e9-8276-0359a429";// build the evm txconst tx =await sdk.rbac.updateRole({roleName: roleName,roleId: roleId});// send using Sdk functionconst receipt =awaitSdk.sendEvmTx({tx: tx,baseUrl:HTTPS_BASE_URL,seed:EVM_PRIVATE});// fetch Role to confirm the name changeconst response =await sdk.rbac.fetchRole({owner:EVM_ADDRESS,roleId: roleId,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});// role id to disableconst roleId ="b68a5589-1284-49e9-8276-0359a429";// build the evm txconst tx =await sdk.rbac.disableRole({roleId: roleId});// send using Sdk functionconst receipt =awaitSdk.sendEvmTx({tx: tx,baseUrl:HTTPS_BASE_URL,seed:EVM_PRIVATE});// Fetch Role to confirm it has been changed to disabledconst response =await sdk.rbac.fetchRole({owner:EVM_ADDRESS,roleId: roleId,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});// self-generated userIdconst userId ="9e8c7866-8435-4b76-8683-709a03c9";// role id to unassign to userconst roleId ="b68a5589-1284-49e9-8276-0359a429";// build the evm txconst tx =await sdk.rbac.unassignRoleToUser({userId: userId,roleId: roleId});// send using Sdk functionconst receipt =awaitSdk.sendEvmTx({tx: tx,baseUrl:HTTPS_BASE_URL,seed:EVM_PRIVATE});// fetch to see it has been unassigned (should throw an error)const response =await sdk.rbac.fetchUserRoles({owner:EVM_ADDRESS,userId: userId,wssBaseUrl:WSS_BASE_URL});