createPermission(permissionName, permissionId, address, seed)
Used to create a new permission within the RBAC (Role-Based Access Control) system.
Parameter Type EVM Substrate Description permissionName string
Required Required Name of the permission to be created. permissionId string
Optional Optional ID of the permission (32 bytes). If not supplied one will be generated for you. seed string
N/A Optional If not set at instance creation, allows user to define who sends the Substrate Transactions.
Create Permission Code Examples
EVM Request
EVM Response
Substrate Request
Substrate Response
import { Sdk } from "@peaq-network/sdk" ;
const HTTPS_BASE_URL = "https://peaq.api.onfinality.io/public" ;
const EVM_PRIVATE = process. env [ "EVM_PRIVATE" ] ;
const sdk = await Sdk . createInstance ( {
baseUrl : HTTPS_BASE_URL ,
chainType : Sdk . ChainType . EVM
} ) ;
const permissionName = "peaq-permission-1" ;
const permission = await sdk. rbac . createPermission ( {
permissionName : permissionName
} ) ;
const receipt = await Sdk . sendEvmTx ( {
tx : permission. tx ,
baseUrl : HTTPS_BASE_URL ,
seed : EVM_PRIVATE
} ) ;
console . log ( permission. permissionId ) ;
The EVM tx returns in a different form than what was used throughout the sdk. The purpose of this is to show the permission-id that was autogenerated if it was not manually set. That way you are able to take note of the permission-id for that permission-name set.
fetchPermission(owner, permissionId, wssBaseUrl)
Fetch a permission at the given permissionId and address.
Parameter Type EVM Substrate Description owner string
Required Required Address representing the owner of the permission permissionId string
Required Required ID of the permission to be fetched. wssBaseUrl string
Required N/A WSS URL used to query RBAC storage.
Fetch Group Code Examples
EVM Request
EVM Response
Substrate Request
Substrate Response
import { Sdk } from "@peaq-network/sdk" ;
const HTTPS_BASE_URL = "https://peaq.api.onfinality.io/public" ;
const WSS_BASE_URL = "wss://peaq.api.onfinality.io/public" ;
const EVM_ADDRESS = process. env [ "EVM_ADDRESS" ] ;
const sdk = await Sdk . createInstance ( {
baseUrl : HTTPS_BASE_URL ,
chainType : Sdk . ChainType . EVM
} ) ;
const permissionId = "31bc8f97-c587-4784-a725-b6c73eed" ;
const response = await sdk. rbac . fetchPermission ( {
owner : EVM_ADDRESS ,
permissionId : permissionId,
wssBaseUrl : WSS_BASE_URL
} ) ;
fetchPermissions(owner, wssBaseUrl)
Used to fetch all the permissions associated with the passed owner address
Parameter Type EVM Substrate Description owner string
Required Required Address representing the owner of all the fetched permissions. wssBaseUrl string
Required N/A WSS URL used to query RBAC storage.
Fetch Permissions Code Examples
EVM Request
EVM Response
Substrate Request
Substrate Response
import { Sdk } from "@peaq-network/sdk" ;
const HTTPS_BASE_URL = "https://peaq.api.onfinality.io/public" ;
const WSS_BASE_URL = "wss://peaq.api.onfinality.io/public" ;
const EVM_ADDRESS = process. env [ "EVM_ADDRESS" ] ;
const sdk = await Sdk . createInstance ( {
baseUrl : HTTPS_BASE_URL ,
chainType : Sdk . ChainType . EVM
} ) ;
const response = await sdk. rbac . fetchPermissions ( {
owner : EVM_ADDRESS ,
wssBaseUrl : WSS_BASE_URL
} ) ;
updatePermission(permissionName, permissionId, address, seed)
Allows the owner to update the permission name.
Parameter Type EVM Substrate Description permissionName string
Required Required Updated permission name. permissionId string
Required Required ID of the permission (32 bytes) to be updated. seed string
N/A Optional If not set at instance creation, allows user to define who sends the Substrate Transactions.
Update Permission Code Examples
EVM Request
EVM Response
Substrate Request
Substrate Response
import { Sdk } from "@peaq-network/sdk" ;
const HTTPS_BASE_URL = "https://peaq.api.onfinality.io/public" ;
const WSS_BASE_URL = "wss://peaq.api.onfinality.io/public" ;
const EVM_ADDRESS = process. env [ "EVM_ADDRESS" ] ;
const EVM_PRIVATE = process. env [ "EVM_PRIVATE" ] ;
const sdk = await Sdk . createInstance ( {
baseUrl : HTTPS_BASE_URL ,
chainType : Sdk . ChainType . EVM
} ) ;
const permissionName = "peaq-permission-new" ;
const permissionId = "31bc8f97-c587-4784-a725-b6c73eed" ;
const tx = await sdk. rbac . updatePermission ( {
permissionName : permissionName,
permissionId : permissionId
} ) ;
const receipt = await Sdk . sendEvmTx ( {
tx : tx,
baseUrl : HTTPS_BASE_URL ,
seed : EVM_PRIVATE
} ) ;
const response = await sdk. rbac . fetchPermission ( {
owner : EVM_ADDRESS ,
permissionId : permissionId,
wssBaseUrl : WSS_BASE_URL
} ) ;
disablePermission(permissionId, address, seed)
Disables a permission within a permission management system.
Parameter Type EVM Substrate Description permissionId string
Required Required The unique identifier (ID) of the permission to be disabled. seed string
N/A Optional If not set at instance creation, allows user to define who sends the Substrate Transactions.
Disable Permission Code Examples
EVM Request
EVM Response
Substrate Request
Substrate Response
import { Sdk } from "@peaq-network/sdk" ;
const HTTPS_BASE_URL = "https://peaq.api.onfinality.io/public" ;
const WSS_BASE_URL = "wss://peaq.api.onfinality.io/public" ;
const EVM_ADDRESS = process. env [ "EVM_ADDRESS" ] ;
const EVM_PRIVATE = process. env [ "EVM_PRIVATE" ] ;
const sdk = await Sdk . createInstance ( {
baseUrl : HTTPS_BASE_URL ,
chainType : Sdk . ChainType . EVM
} ) ;
const permissionId = "31bc8f97-c587-4784-a725-b6c73eed" ;
const tx = await sdk. rbac . disablePermission ( {
permissionId : permissionId
} ) ;
const receipt = await Sdk . sendEvmTx ( {
tx : tx,
baseUrl : HTTPS_BASE_URL ,
seed : EVM_PRIVATE
} ) ;
const response = await sdk. rbac . fetchPermission ( {
owner : EVM_ADDRESS ,
permissionId : permissionId,
wssBaseUrl : WSS_BASE_URL
} ) ;
assignPermissionToRole(permissionId, roleId, address, seed)
This function allows to assign a permission to a role in a permission management system.
Parameter Type EVM Substrate Description permissionId string
Required Required ID of the permission to be assigned to the role. roleId string
Required Required ID of the role to which the permission will be assigned. seed string
N/A Optional If not set at instance creation, allows user to define who sends the Substrate Transactions.
Assign Permission to Role Code Examples
EVM Request
EVM Response
Substrate Request
Substrate Response
import { Sdk } from "@peaq-network/sdk" ;
const HTTPS_BASE_URL = "https://peaq.api.onfinality.io/public" ;
const EVM_PRIVATE = process. env [ "EVM_PRIVATE" ] ;
const sdk = await Sdk . createInstance ( {
baseUrl : HTTPS_BASE_URL ,
chainType : Sdk . ChainType . EVM
} ) ;
const permissionId = "31bc8f97-c587-4784-a725-b6c73eed" ;
const roleId = "b68a5589-1284-49e9-8276-0359a429" ;
const tx = await sdk. rbac . assignPermissionToRole ( {
permissionId : permissionId,
roleId : roleId
} ) ;
const receipt = await Sdk . sendEvmTx ( {
tx : tx,
baseUrl : HTTPS_BASE_URL ,
seed : EVM_PRIVATE
} ) ;
fetchRolePermissions(owner, roleId, wssBaseUrl)
Designed to retrieve permissions associated with a specific role.
Parameter Type EVM Substrate Description owner string
Required Required Address of the owner of the roles. roleId string
Required Required ID of the role for whom permissions are to be fetched. wssBaseUrl string
Required N/A WSS URL used to query RBAC storage.
Fetch Role Permissions Code Examples
EVM Request
EVM Response
Substrate Request
Substrate Response
import { Sdk } from "@peaq-network/sdk" ;
const HTTPS_BASE_URL = "https://peaq.api.onfinality.io/public" ;
const WSS_BASE_URL = "wss://peaq.api.onfinality.io/public" ;
const EVM_ADDRESS = process. env [ "EVM_ADDRESS" ] ;
const sdk = await Sdk . createInstance ( {
baseUrl : HTTPS_BASE_URL ,
chainType : Sdk . ChainType . EVM
} ) ;
const roleId = "b68a5589-1284-49e9-8276-0359a429" ;
const response = await sdk. rbac . fetchRolePermissions ( {
owner : EVM_ADDRESS ,
roleId : roleId,
wssBaseUrl : WSS_BASE_URL
} ) ;
unassignPermissionToRole(permissionId, roleId, address, seed)
This function allows to unassign a permission from a role in a permission management system.
Parameter Type EVM Substrate Description permissionId string
Required Required ID of the permission to be unassigned. roleId string
Required Required ID of the role from which to unassign the permission. seed string
N/A Optional If not set at instance creation, allows user to define who sends the Substrate Transactions.
Unassign Permission from Role Code Examples
EVM Request
EVM Response
Substrate Request
Substrate Response
import { Sdk } from "@peaq-network/sdk" ;
const HTTPS_BASE_URL = "https://peaq.api.onfinality.io/public" ;
const WSS_BASE_URL = "wss://peaq.api.onfinality.io/public" ;
const EVM_ADDRESS = process. env [ "EVM_ADDRESS" ] ;
const EVM_PRIVATE = process. env [ "EVM_PRIVATE" ] ;
const sdk = await Sdk . createInstance ( {
baseUrl : HTTPS_BASE_URL ,
chainType : Sdk . ChainType . EVM
} ) ;
const permissionId = "31bc8f97-c587-4784-a725-b6c73eed" ;
const roleId = "b68a5589-1284-49e9-8276-0359a429" ;
const tx = await sdk. rbac . unassignPermissionToRole ( {
permissionId : permissionId,
roleId : roleId
} ) ;
const receipt = await Sdk . sendEvmTx ( {
tx : tx,
baseUrl : HTTPS_BASE_URL ,
seed : EVM_PRIVATE
} ) ;
const response = await sdk. rbac . fetchRolePermissions ( {
owner : EVM_ADDRESS ,
roleId : roleId,
wssBaseUrl : WSS_BASE_URL
} ) ;
fetchUserPermission(owner, userId, wssBaseUrl)
Fetches the permissions associated with a user.
Parameter Type EVM Substrate Description owner string
Required Required Address of the owner of the permissions. userId string
Required Required ID of the user for whom you want to fetch permissions. wssBaseUrl string
Required N/A WSS URL used to query RBAC storage.
In order to fetch a user permission the following flow must take place:
Create permission
Create role
Assign permission to role
Assign role to user
Fetch user permissions
The following code shows this flow.
Fetch User Permissions Code Examples
EVM Request
EVM Response
Substrate Request
Substrate Response
import { Sdk } from "@peaq-network/sdk" ;
const HTTPS_BASE_URL = "https://peaq.api.onfinality.io/public" ;
const WSS_BASE_URL = "wss://peaq.api.onfinality.io/public" ;
const EVM_ADDRESS = process. env [ "EVM_ADDRESS" ] ;
const EVM_PRIVATE = process. env [ "EVM_PRIVATE" ] ;
const sdk = await Sdk . createInstance ( {
baseUrl : HTTPS_BASE_URL ,
chainType : Sdk . ChainType . EVM
} ) ;
const permissionName = "peaq-permission-2" ;
const txPermission = await sdk. rbac . createPermission ( { permissionName : permissionName} ) ;
await Sdk . sendEvmTx ( { tx : txPermission. tx , baseUrl : HTTPS_BASE_URL , seed : EVM_PRIVATE } ) ;
const roleName = "peaq-role-2" ;
const txRole = await sdk. rbac . createRole ( { roleName : roleName} ) ;
await Sdk . sendEvmTx ( { tx : txRole. tx , baseUrl : HTTPS_BASE_URL , seed : EVM_PRIVATE } ) ;
const tx = await sdk. rbac . assignPermissionToRole ( { permissionId : txPermission. permissionId , roleId : txRole. roleId } ) ;
await Sdk . sendEvmTx ( { tx : tx, baseUrl : HTTPS_BASE_URL , seed : EVM_PRIVATE } ) ;
const userId = "9e8c7866-8435-4b76-8683-709a03c9" ;
const tx2 = await sdk. rbac . assignRoleToUser ( { userId : userId, roleId : txRole. roleId } ) ;
await Sdk . sendEvmTx ( { tx : tx2, baseUrl : HTTPS_BASE_URL , seed : EVM_PRIVATE } ) ;
const response = await sdk. rbac . fetchUserPermissions ( { owner : EVM_ADDRESS , userId : userId, wssBaseUrl : WSS_BASE_URL } ) ;
fetchGroupPermissions(owner, groupId, wssBaseUrl)
Fetches the permissions associated with a group.
Parameter Type EVM Substrate Description owner string
Required Required Address of the owner of the permissions. groupId string
Required Required ID of the group for whom you want to fetch permissions. wssBaseUrl string
Required N/A WSS URL used to query RBAC storage.
In order to fetch a group permission the following flow must take place:
Create permission
Create role
Assign permission to role
Create group
Assign role to group
Fetch group permissions
The following code shows this flow.
Fetch Group Permissions Code Examples
EVM Request
EVM Response
Substrate Request
Substrate Response
import { Sdk } from "@peaq-network/sdk" ;
const HTTPS_BASE_URL = "https://peaq.api.onfinality.io/public" ;
const WSS_BASE_URL = "wss://peaq.api.onfinality.io/public" ;
const EVM_ADDRESS = process. env [ "EVM_ADDRESS" ] ;
const EVM_PRIVATE = process. env [ "EVM_PRIVATE" ] ;
const sdk = await Sdk . createInstance ( {
baseUrl : HTTPS_BASE_URL ,
chainType : Sdk . ChainType . EVM
} ) ;
const permissionName = "peaq-permission-2" ;
const txPermission = await sdk. rbac . createPermission ( { permissionName : permissionName} ) ;
await Sdk . sendEvmTx ( { tx : txPermission. tx , baseUrl : HTTPS_BASE_URL , seed : EVM_PRIVATE } ) ;
const roleName = "peaq-role-2" ;
const txRole = await sdk. rbac . createRole ( { roleName : roleName} ) ;
await Sdk . sendEvmTx ( { tx : txRole. tx , baseUrl : HTTPS_BASE_URL , seed : EVM_PRIVATE } ) ;
const tx = await sdk. rbac . assignPermissionToRole ( { permissionId : txPermission. permissionId , roleId : txRole. roleId } ) ;
await Sdk . sendEvmTx ( { tx : tx, baseUrl : HTTPS_BASE_URL , seed : EVM_PRIVATE } ) ;
const groupName = "peaq-group-2" ;
const txGroup = await sdk. rbac . createGroup ( { groupName : groupName} ) ;
await Sdk . sendEvmTx ( { tx : txGroup. tx , baseUrl : HTTPS_BASE_URL , seed : EVM_PRIVATE } ) ;
const tx2 = await sdk. rbac . assignRoleToGroup ( { groupId : txGroup. groupId , roleId : txRole. roleId } ) ;
await Sdk . sendEvmTx ( { tx : tx2, baseUrl : HTTPS_BASE_URL , seed : EVM_PRIVATE } ) ;
const response = await sdk. rbac . fetchGroupPermissions ( { owner : EVM_ADDRESS , groupId : txGroup. groupId , wssBaseUrl : WSS_BASE_URL } ) ;