createRole(roleName, roleId, seed)
Create a new role in the peaq network’s Role-Based Access Control (RBAC) system.
Parameter Type EVM Substrate Description roleName string
Required Required Name of the role to be created. roleId string
Optional Optional ID of the role (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 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 roleName = "peaq-role-1" ;
const role = await sdk . rbac . createRole ({
roleName: roleName
});
// Send using Sdk function
const receipt = await Sdk . sendEvmTx ({
tx: role . tx ,
baseUrl: HTTPS_BASE_URL ,
seed: EVM_PRIVATE
});
// Log to see what the auto generated roleId is
console . 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.
fetchRole(owner, roleId, wssBaseUrl)
Fetch a role at the given roleId and address associated.
Parameter Type EVM Substrate Description owner string
Required Required Address representing the owner of the role. roleId string
Required Required ID of the role to be fetched. wssBaseUrl string
Required N/A WSS URL used to query RBAC storage. Substrate WSS is stored at instance creation.
Fetch 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 sdk = await Sdk . createInstance ({
baseUrl: HTTPS_BASE_URL ,
chainType: Sdk . ChainType . EVM
});
// example of a previously created role id
const roleId = "b68a5589-1284-49e9-8276-0359a429" ;
const response = await sdk . rbac . fetchRole ({
owner: EVM_ADDRESS ,
roleId: roleId ,
wssBaseUrl: WSS_BASE_URL
});
fetchRoles(owner, wssBaseUrl)
Used to fetch all the roles associated with the passed owner address.
Parameter Type EVM Substrate Description owner string
Required Required Address that represents the owner of all the fetched roles. wssBaseUrl string
Required N/A WSS URL used to query RBAC storage. Substrate WSS is stored at instance creation.
Fetch Roles 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 . fetchRoles ({
owner: EVM_ADDRESS ,
wssBaseUrl: WSS_BASE_URL
});
updateRole(roleName, roleId, seed)
Allows the owner to update the role name.
Parameter Type EVM Substrate Description roleName string
Required Required Updated role name. roleId string
Required Required ID of the role (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 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
});
// new role name that will be set
const roleName = "peaq-role-new" ;
// example of a previously created role id
const roleId = "b68a5589-1284-49e9-8276-0359a429" ;
// build the evm tx
const tx = await sdk . rbac . updateRole ({
roleName: roleName ,
roleId: roleId
});
// send using Sdk function
const receipt = await Sdk . sendEvmTx ({
tx: tx ,
baseUrl: HTTPS_BASE_URL ,
seed: EVM_PRIVATE
});
// fetch Role to confirm the name change
const response = await sdk . rbac . fetchRole ({
owner: EVM_ADDRESS ,
roleId: roleId ,
wssBaseUrl: WSS_BASE_URL
});
disableRole(roleId, seed)
Disables a role within a permission management system.
Parameter Type EVM Substrate Description roleId string
Required Required The unique identifier (ID) of the role to be disabled. seed string
N/A Optional If not set at instance creation, allows user to define who sends the Substrate Transactions.
Disable 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
});
// role id to disable
const roleId = "b68a5589-1284-49e9-8276-0359a429" ;
// build the evm tx
const tx = await sdk . rbac . disableRole ({
roleId: roleId
});
// send using Sdk function
const receipt = await Sdk . sendEvmTx ({
tx: tx ,
baseUrl: HTTPS_BASE_URL ,
seed: EVM_PRIVATE
});
// Fetch Role to confirm it has been changed to disabled
const response = await sdk . rbac . fetchRole ({
owner: EVM_ADDRESS ,
roleId: roleId ,
wssBaseUrl: WSS_BASE_URL
});
assignRoleToUser(userId, roleId, seed)
This function allows to assign a specific role to a user in a permission management system.
Parameter Type EVM Substrate Description userId string
Required Required The unique identifier of the user to whom the role will be assigned. ID created by user and must be 32 bytes. roleId string
Required Required ID of the role that will be assigned to the user. seed string
N/A Optional If not set at instance creation, allows user to define who sends the Substrate Transactions.
Assign Role to User 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
});
// self-generated userId
const userId = "9e8c7866-8435-4b76-8683-709a03c9" ;
// role id to assign to user
const roleId = "b68a5589-1284-49e9-8276-0359a429" ;
// build the evm tx
const tx = await sdk . rbac . assignRoleToUser ({
userId: userId ,
roleId: roleId
});
// send using Sdk function
const receipt = await Sdk . sendEvmTx ({
tx: tx ,
baseUrl: HTTPS_BASE_URL ,
seed: EVM_PRIVATE
});
fetchUserRoles(owner, userId, wssBaseUrl)
Designed to retrieve roles associated with a specific user from the network’s RBAC (Role-Based Access Control) system.
Parameter Type EVM Substrate Description owner string
Required Required Address of the owner of the roles. This is typically the account that manages the roles and permissions. userId string
Required Required Unique identifier of the user for whom roles are to be fetched. wssBaseUrl string
Required N/A WSS URL used to query RBAC storage. Substrate WSS is stored at instance creation.
Fetch User Roles 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 userId = "9e8c7866-8435-4b76-8683-709a03c9" ;
const response = await sdk . rbac . fetchUserRoles ({
owner: EVM_ADDRESS ,
userId: userId ,
wssBaseUrl: WSS_BASE_URL
});
unassignRoleToUser(userId, roleId, seed)
This function allows to unassign a specific role to a user in a permission management system.
Parameter Type EVM Substrate Description userId string
Required Required ID of the user from which the role should be unassigned. roleId string
Required Required ID of the role that needs to be unassigned. seed string
N/A Optional If not set at instance creation, allows user to define who sends the Substrate Transactions.
Unassign Role to User 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
});
// self-generated userId
const userId = "9e8c7866-8435-4b76-8683-709a03c9" ;
// role id to unassign to user
const roleId = "b68a5589-1284-49e9-8276-0359a429" ;
// build the evm tx
const tx = await sdk . rbac . unassignRoleToUser ({
userId: userId ,
roleId: roleId
});
// send using Sdk function
const receipt = await Sdk . 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
});