createRole(roleName, roleId, seed)

Create a new role in the peaq network’s Role-Based Access Control (RBAC) system.

ParameterTypeEVMSubstrateDescription
roleNamestringRequiredRequiredName of the role to be created.
roleIdstringOptionalOptionalID of the role (32 bytes). If not supplied one will be generated for you.
seedstringN/AOptionalIf not set at instance creation, allows user to define who sends the Substrate Transactions.

Create Role Code Examples

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.

ParameterTypeEVMSubstrateDescription
ownerstringRequiredRequiredAddress representing the owner of the role.
roleIdstringRequiredRequiredID of the role to be fetched.
wssBaseUrlstringRequiredN/AWSS URL used to query RBAC storage. Substrate WSS is stored at instance creation.

Fetch Role Code Examples

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.

ParameterTypeEVMSubstrateDescription
ownerstringRequiredRequiredAddress that represents the owner of all the fetched roles.
wssBaseUrlstringRequiredN/AWSS URL used to query RBAC storage. Substrate WSS is stored at instance creation.

Fetch Roles Code Examples

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.

ParameterTypeEVMSubstrateDescription
roleNamestringRequiredRequiredUpdated role name.
roleIdstringRequiredRequiredID of the role (32 bytes) to be updated.
seedstringN/AOptionalIf not set at instance creation, allows user to define who sends the Substrate Transactions.

Update Role Code Examples

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.

ParameterTypeEVMSubstrateDescription
roleIdstringRequiredRequiredThe unique identifier (ID) of the role to be disabled.
seedstringN/AOptionalIf not set at instance creation, allows user to define who sends the Substrate Transactions.

Disable Role Code Examples

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.

ParameterTypeEVMSubstrateDescription
userIdstringRequiredRequiredThe unique identifier of the user to whom the role will be assigned. ID created by user and must be 32 bytes.
roleIdstringRequiredRequiredID of the role that will be assigned to the user.
seedstringN/AOptionalIf not set at instance creation, allows user to define who sends the Substrate Transactions.

Assign Role to User Code Examples

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.

ParameterTypeEVMSubstrateDescription
ownerstringRequiredRequiredAddress of the owner of the roles. This is typically the account that manages the roles and permissions.
userIdstringRequiredRequiredUnique identifier of the user for whom roles are to be fetched.
wssBaseUrlstringRequiredN/AWSS URL used to query RBAC storage. Substrate WSS is stored at instance creation.

Fetch User Roles Code Examples

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.

ParameterTypeEVMSubstrateDescription
userIdstringRequiredRequiredID of the user from which the role should be unassigned.
roleIdstringRequiredRequiredID of the role that needs to be unassigned.
seedstringN/AOptionalIf not set at instance creation, allows user to define who sends the Substrate Transactions.

Unassign Role to User Code Examples

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
});