createPermission(permissionName, permissionId, address, seed)
Creates a new permission in 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. |
| address | string | N/A | Optional | Only used to look up the nonce; defaults to the address derived from seed. The transaction is always signed by the seed account, so leave this unset. |
| seed | string | N/A | Optional | If not set at instance creation, allows user to define who sends the Substrate Transactions. |
Create Permission Code Examples
import { Sdk } from "@peaq-network/sdk";
const HTTPS_BASE_URL = "https://quicknode1.peaq.xyz";
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
});
// Send using Sdk function
const receipt = await Sdk.sendEvmTx({
tx: permission.tx,
baseUrl: HTTPS_BASE_URL,
seed: EVM_PRIVATE
});
// log to see the generated id
console.log(permission.permissionId);
// sdk.rbac.createPermission({}) return object
{
tx: {
to: '0x0000000000000000000000000000000000000802',
data: '0x67a2e51533316263386639372d633538372d343738342d613732352d623663373365656400000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000011706561712d7065726d697373696f6e2d31000000000000000000000000000000'
},
permissionId: '31bc8f97-c587-4784-a725-b6c73eed'
}
// sendEvmTx({}) return object
TransactionReceipt {
provider: JsonRpcProvider {},
to: '0x0000000000000000000000000000000000000802',
from: '0x9Eeab1aCcb1A701aEfAB00F3b8a275a39646641C',
contractAddress: null,
hash: '0x66acb0dde4190d38536318a95376535b11d1c995dfa264e4c70690fa364b058d',
index: 0,
blockHash: '0xbe62e0bdb0b98645280bda895ff6d8a62ccc511d8c69c95d8c3494eb8be32be3',
blockNumber: 4501439,
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020008000000000000000000000000000000000008000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000',
gasUsed: 34498n,
blobGasUsed: null,
cumulativeGasUsed: 34498n,
gasPrice: 100000000000n,
blobGasPrice: null,
type: 2,
status: 1,
root: undefined
}
import { Sdk } from "@peaq-network/sdk";
const WSS_BASE_URL = "wss://quicknode1.peaq.xyz";
const SUBSTRATE_SEED = process.env["SUBSTRATE_SEED"];
const sdk = await Sdk.createInstance({
baseUrl: WSS_BASE_URL,
chainType: Sdk.ChainType.SUBSTRATE,
seed: SUBSTRATE_SEED
});
const permissionName = "peaq-permission-1";
const response = await sdk.rbac.createPermission({
permissionName: permissionName
});
// disconnect when finished
await sdk.disconnect();
// sdk.rbac.createPermission({}) return object
{ permissionId: '77395752-8588-47c5-8bd5-0d2bf273' }
createPermission returns the transaction together with the permissionId, as createRole and createGroup do with their IDs; the other write calls return the transaction alone. That is how you read back an ID the SDK generated for you.
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 Permission Code Examples
import { Sdk } from "@peaq-network/sdk";
const HTTPS_BASE_URL = "https://quicknode1.peaq.xyz";
const WSS_BASE_URL = "wss://quicknode1.peaq.xyz";
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 permission id
const permissionId = "31bc8f97-c587-4784-a725-b6c73eed";
const response = await sdk.rbac.fetchPermission({
owner: EVM_ADDRESS,
permissionId: permissionId,
wssBaseUrl: WSS_BASE_URL
});
// sdk.rbac.fetchPermission({}) response object
{
id: '31bc8f97-c587-4784-a725-b6c73eed',
name: 'peaq-permission-1',
enabled: true
}
import { Sdk } from "@peaq-network/sdk";
const WSS_BASE_URL = "wss://quicknode1.peaq.xyz";
const SUBSTRATE_ADDRESS = process.env["SUBSTRATE_ADDRESS"];
const sdk = await Sdk.createInstance({
baseUrl: WSS_BASE_URL,
chainType: Sdk.ChainType.SUBSTRATE
});
const permissionId = "77395752-8588-47c5-8bd5-0d2bf273";
const response = await sdk.rbac.fetchPermission({
owner: SUBSTRATE_ADDRESS,
permissionId: permissionId
});
// disconnect when finished
await sdk.disconnect();
// sdk.rbac.fetchPermission({}) response object
{
id: '77395752-8588-47c5-8bd5-0d2bf273',
name: 'peaq-permission-1',
enabled: true
}
fetchPermissions(owner, wssBaseUrl)
Fetches every permission owned by the given 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
import { Sdk } from "@peaq-network/sdk";
const HTTPS_BASE_URL = "https://quicknode1.peaq.xyz";
const WSS_BASE_URL = "wss://quicknode1.peaq.xyz";
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
});
// sdk.rbac.fetchPermissions({}) response object
[
{
id: '88dec9d0-354e-4ab6-9856-7a7eb45c',
name: 'permission-name-123',
enabled: true
},
...
{
id: '31bc8f97-c587-4784-a725-b6c73eed',
name: 'peaq-permission-1',
enabled: true
}
]
import { Sdk } from "@peaq-network/sdk";
const WSS_BASE_URL = "wss://quicknode1.peaq.xyz";
const SUBSTRATE_ADDRESS = process.env["SUBSTRATE_ADDRESS"];
const sdk = await Sdk.createInstance({
baseUrl: WSS_BASE_URL,
chainType: Sdk.ChainType.SUBSTRATE
});
const response = await sdk.rbac.fetchPermissions({
owner: SUBSTRATE_ADDRESS
});
// disconnect when finished
await sdk.disconnect();
// sdk.rbac.fetchPermissions({}) response object
[
{
id: '21f7ad5f-0f41-40d5-b9f6-7ce0aad3',
name: 'permission-name-123',
enabled: true
},
...
{
id: '77395752-8588-47c5-8bd5-0d2bf273',
name: 'peaq-permission-1',
enabled: true
}
]
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. |
| address | string | N/A | Optional | Only used to look up the nonce; defaults to the address derived from seed. The transaction is always signed by the seed account, so leave this unset. |
| seed | string | N/A | Optional | If not set at instance creation, allows user to define who sends the Substrate Transactions. |
Update Permission Code Examples
import { Sdk } from "@peaq-network/sdk";
const HTTPS_BASE_URL = "https://quicknode1.peaq.xyz";
const WSS_BASE_URL = "wss://quicknode1.peaq.xyz";
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 permission name that will be set
const permissionName = "peaq-permission-new";
// example of a previously created permission id
const permissionId = "31bc8f97-c587-4784-a725-b6c73eed";
// build the evm tx
const tx = await sdk.rbac.updatePermission({
permissionName: permissionName,
permissionId: permissionId
});
// send using Sdk function
const receipt = await Sdk.sendEvmTx({
tx: tx,
baseUrl: HTTPS_BASE_URL,
seed: EVM_PRIVATE
});
// fetch permission to confirm the name change
const response = await sdk.rbac.fetchPermission({
owner: EVM_ADDRESS,
permissionId: permissionId,
wssBaseUrl: WSS_BASE_URL
});
// sdk.rbac.updatePermission({}) return object
{
to: '0x0000000000000000000000000000000000000802',
data: '0xb0c5b5ad33316263386639372d633538372d343738342d613732352d623663373365656400000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000013706561712d7065726d697373696f6e2d6e657700000000000000000000000000'
}
import { Sdk } from "@peaq-network/sdk";
const WSS_BASE_URL = "wss://quicknode1.peaq.xyz";
const SUBSTRATE_ADDRESS = process.env["SUBSTRATE_ADDRESS"];
const SUBSTRATE_SEED = process.env["SUBSTRATE_SEED"];
const sdk = await Sdk.createInstance({
baseUrl: WSS_BASE_URL,
chainType: Sdk.ChainType.SUBSTRATE,
seed: SUBSTRATE_SEED
});
// new permission name that will be set
const permissionName = "peaq-permission-new";
// example of a previously created permission id
const permissionId = "77395752-8588-47c5-8bd5-0d2bf273";
const response = await sdk.rbac.updatePermission({
permissionName: permissionName,
permissionId: permissionId
});
// Fetch permission to confirm the name change
const fetchedPermission = await sdk.rbac.fetchPermission({
owner: SUBSTRATE_ADDRESS,
permissionId: permissionId
});
// disconnect when finished
await sdk.disconnect();
// sdk.rbac.updatePermission({}) return object
{
message: 'Successfully update permission 77395752-8588-47c5-8bd5-0d2bf273 with new name: peaq-permission-new'
}
disablePermission(permissionId, address, seed)
Disables a permission.| Parameter | Type | EVM | Substrate | Description |
|---|---|---|---|---|
| permissionId | string | Required | Required | The unique identifier (ID) of the permission to be disabled. |
| address | string | N/A | Optional | Only used to look up the nonce; defaults to the address derived from seed. The transaction is always signed by the seed account, so leave this unset. |
| seed | string | N/A | Optional | If not set at instance creation, allows user to define who sends the Substrate Transactions. |
Disable Permission Code Examples
import { Sdk } from "@peaq-network/sdk";
const HTTPS_BASE_URL = "https://quicknode1.peaq.xyz";
const WSS_BASE_URL = "wss://quicknode1.peaq.xyz";
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
});
// permission id to disable
const permissionId = "31bc8f97-c587-4784-a725-b6c73eed";
// build the evm tx
const tx = await sdk.rbac.disablePermission({
permissionId: permissionId
});
// send using Sdk function
const receipt = await Sdk.sendEvmTx({
tx: tx,
baseUrl: HTTPS_BASE_URL,
seed: EVM_PRIVATE
});
// Fetch permission to confirm it has been changed to disabled
const response = await sdk.rbac.fetchPermission({
owner: EVM_ADDRESS,
permissionId: permissionId,
wssBaseUrl: WSS_BASE_URL
});
// sdk.rbac.disablePermission({}) return object
{
to: '0x0000000000000000000000000000000000000802',
data: '0x727e011e33316263386639372d633538372d343738342d613732352d6236633733656564'
}
import { Sdk } from "@peaq-network/sdk";
const WSS_BASE_URL = "wss://quicknode1.peaq.xyz";
const SUBSTRATE_ADDRESS = process.env["SUBSTRATE_ADDRESS"];
const SUBSTRATE_SEED = process.env["SUBSTRATE_SEED"];
const sdk = await Sdk.createInstance({
baseUrl: WSS_BASE_URL,
chainType: Sdk.ChainType.SUBSTRATE,
seed: SUBSTRATE_SEED
});
// permission id to disable
const permissionId = "77395752-8588-47c5-8bd5-0d2bf273";
// execute the extrinsic
const response = await sdk.rbac.disablePermission({
permissionId: permissionId
});
// Fetch permission to confirm it has been changed to disabled
const fetchedPermission = await sdk.rbac.fetchPermission({
owner: SUBSTRATE_ADDRESS,
permissionId: permissionId,
});
// disconnect when finished
await sdk.disconnect();
// sdk.rbac.disablePermission({}) return object
{
message: 'Successfully disable permission 77395752-8588-47c5-8bd5-0d2bf273'
}
assignPermissionToRole(permissionId, roleId, address, seed)
Assigns a permission to a role.| 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. |
| address | string | N/A | Optional | Only used to look up the nonce; defaults to the address derived from seed. The transaction is always signed by the seed account, so leave this unset. |
| 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
import { Sdk } from "@peaq-network/sdk";
const HTTPS_BASE_URL = "https://quicknode1.peaq.xyz";
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";
// build the evm tx
const tx = await sdk.rbac.assignPermissionToRole({
permissionId: permissionId,
roleId: roleId
});
// send using Sdk function
const receipt = await Sdk.sendEvmTx({
tx: tx,
baseUrl: HTTPS_BASE_URL,
seed: EVM_PRIVATE
});
// sdk.rbac.assignPermissionToRole({}) return object
{
to: '0x0000000000000000000000000000000000000802',
data: '0x404147f133316263386639372d633538372d343738342d613732352d623663373365656462363861353538392d313238342d343965392d383237362d3033353961343239'
}
import { Sdk } from "@peaq-network/sdk";
const WSS_BASE_URL = "wss://quicknode1.peaq.xyz";
const SUBSTRATE_SEED = process.env["SUBSTRATE_SEED"];
const sdk = await Sdk.createInstance({
baseUrl: WSS_BASE_URL,
chainType: Sdk.ChainType.SUBSTRATE,
seed: SUBSTRATE_SEED
});
const permissionId = "77395752-8588-47c5-8bd5-0d2bf273";
const roleId = "bc3f20d5-c519-4048-8db1-4bbf48dc";
const response = await sdk.rbac.assignPermissionToRole({
permissionId: permissionId,
roleId: roleId
});
// disconnect when finished
await sdk.disconnect();
// sdk.rbac.assignPermissionToRole({}) return object
{
message: 'Successfully assign permission 77395752-8588-47c5-8bd5-0d2bf273 to role bc3f20d5-c519-4048-8db1-4bbf48dc'
}
fetchRolePermissions(owner, roleId, wssBaseUrl)
Fetches the permissions assigned to a 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
import { Sdk } from "@peaq-network/sdk";
const HTTPS_BASE_URL = "https://quicknode1.peaq.xyz";
const WSS_BASE_URL = "wss://quicknode1.peaq.xyz";
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
});
// sdk.rbac.fetchRolePermissions({}) return object
[
{
permission: '31bc8f97-c587-4784-a725-b6c73eed',
role: 'b68a5589-1284-49e9-8276-0359a429'
}
]
import { Sdk } from "@peaq-network/sdk";
const WSS_BASE_URL = "wss://quicknode1.peaq.xyz";
const SUBSTRATE_ADDRESS = process.env["SUBSTRATE_ADDRESS"];
const sdk = await Sdk.createInstance({
baseUrl: WSS_BASE_URL,
chainType: Sdk.ChainType.SUBSTRATE
});
const roleId = "bc3f20d5-c519-4048-8db1-4bbf48dc";
const response = await sdk.rbac.fetchRolePermissions({
owner: SUBSTRATE_ADDRESS,
roleId: roleId
});
// disconnect when finished
await sdk.disconnect();
// sdk.rbac.fetchRolePermissions({}) return object
[
{
permission: '77395752-8588-47c5-8bd5-0d2bf273',
role: 'bc3f20d5-c519-4048-8db1-4bbf48dc'
}
]
unassignPermissionToRole(permissionId, roleId, address, seed)
Removes a permission from a role.| 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. |
| address | string | N/A | Optional | Only used to look up the nonce; defaults to the address derived from seed. The transaction is always signed by the seed account, so leave this unset. |
| 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
import { Sdk } from "@peaq-network/sdk";
const HTTPS_BASE_URL = "https://quicknode1.peaq.xyz";
const WSS_BASE_URL = "wss://quicknode1.peaq.xyz";
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
});
// 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
const response = await sdk.rbac.fetchRolePermissions({
owner: EVM_ADDRESS,
roleId: roleId,
wssBaseUrl: WSS_BASE_URL
});
// sdk.rbac.unassignPermissionToRole({}) return object
{
to: '0x0000000000000000000000000000000000000802',
data: '0xba427c9e33316263386639372d633538372d343738342d613732352d623663373365656462363861353538392d313238342d343965392d383237362d3033353961343239'
}
import { Sdk } from "@peaq-network/sdk";
const WSS_BASE_URL = "wss://quicknode1.peaq.xyz";
const SUBSTRATE_ADDRESS = process.env["SUBSTRATE_ADDRESS"];
const SUBSTRATE_SEED = process.env["SUBSTRATE_SEED"];
const sdk = await Sdk.createInstance({
baseUrl: WSS_BASE_URL,
chainType: Sdk.ChainType.SUBSTRATE,
seed: SUBSTRATE_SEED
});
const permissionId = "77395752-8588-47c5-8bd5-0d2bf273";
const roleId = "bc3f20d5-c519-4048-8db1-4bbf48dc";
const response = await sdk.rbac.unassignPermissionToRole({
permissionId: permissionId,
roleId: roleId
});
// fetch to see it has been unassigned
const fetchedRolePermissions = await sdk.rbac.fetchRolePermissions({
owner: SUBSTRATE_ADDRESS,
roleId: roleId
});
// disconnect when finished
await sdk.disconnect();
// sdk.rbac.unassignPermissionToRole({}) return object
{
message: 'Successfully unassign role: bc3f20d5-c519-4048-8db1-4bbf48dc from permission: 77395752-8588-47c5-8bd5-0d2bf273'
}
fetchUserPermissions(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. |
- Create permission
- Create role
- Assign permission to role
- Assign role to user
- Fetch user permissions
Fetch User Permissions Code Examples
import { Sdk } from "@peaq-network/sdk";
const HTTPS_BASE_URL = "https://quicknode1.peaq.xyz";
const WSS_BASE_URL = "wss://quicknode1.peaq.xyz";
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
});
// 1. Create a permission
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});
// 2. Create a role
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});
// 3. Assign permission to role
const tx = await sdk.rbac.assignPermissionToRole({permissionId: txPermission.permissionId, roleId: txRole.roleId});
await Sdk.sendEvmTx({tx: tx, baseUrl: HTTPS_BASE_URL, seed: EVM_PRIVATE});
// 4. Assign role to user
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});
// 5. Fetch user permissions
const response = await sdk.rbac.fetchUserPermissions({owner: EVM_ADDRESS, userId: userId, wssBaseUrl: WSS_BASE_URL});
// sdk.rbac.fetchUserPermissions({}) return object
[
{
id: '763207f6-32ef-4236-969d-d1b81ac4',
name: 'peaq-permission-2',
enabled: true
}
]
import { Sdk } from "@peaq-network/sdk";
const WSS_BASE_URL = "wss://quicknode1.peaq.xyz";
const SUBSTRATE_ADDRESS = process.env["SUBSTRATE_ADDRESS"];
const SUBSTRATE_SEED = process.env["SUBSTRATE_SEED"];
const sdk = await Sdk.createInstance({
baseUrl: WSS_BASE_URL,
chainType: Sdk.ChainType.SUBSTRATE,
seed: SUBSTRATE_SEED
});
// 1. Create a permission
const permissionName = "peaq-permission-2";
const txPermission = await sdk.rbac.createPermission({permissionName: permissionName});
// 2. Create a role
const roleName = "peaq-role-2";
const txRole = await sdk.rbac.createRole({roleName: roleName});
// 3. Assign permission to role
const p2rResp = await sdk.rbac.assignPermissionToRole({permissionId: txPermission.permissionId, roleId: txRole.roleId});
// 4. Assign role to user
const userId = "9e8c7866-8435-4b76-8683-709a03c9";
const r2uResp = await sdk.rbac.assignRoleToUser({userId: userId, roleId: txRole.roleId});
// 5. Fetch user permissions
const response = await sdk.rbac.fetchUserPermissions({owner: SUBSTRATE_ADDRESS, userId: userId});
// disconnect when finished
await sdk.disconnect();
// sdk.rbac.fetchUserPermissions({}) return object
[
{
id: 'fc49ee05-f0ad-47ce-b336-62efdfec',
name: 'peaq-permission-2',
enabled: true
}
]
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. |
- Create permission
- Create role
- Assign permission to role
- Create group
- Assign role to group
- Fetch group permissions
Fetch Group Permissions Code Examples
import { Sdk } from "@peaq-network/sdk";
const HTTPS_BASE_URL = "https://quicknode1.peaq.xyz";
const WSS_BASE_URL = "wss://quicknode1.peaq.xyz";
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
});
// 1. Create a permission
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});
// 2. Create a role
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});
// 3. Assign permission to role
const tx = await sdk.rbac.assignPermissionToRole({permissionId: txPermission.permissionId, roleId: txRole.roleId});
await Sdk.sendEvmTx({tx: tx, baseUrl: HTTPS_BASE_URL, seed: EVM_PRIVATE});
// 4. Create group
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});
// 5. Assign role to group
const tx2 = await sdk.rbac.assignRoleToGroup({groupId: txGroup.groupId, roleId: txRole.roleId});
await Sdk.sendEvmTx({tx: tx2, baseUrl: HTTPS_BASE_URL, seed: EVM_PRIVATE});
// 6. Fetch group permissions
const response = await sdk.rbac.fetchGroupPermissions({owner: EVM_ADDRESS, groupId: txGroup.groupId, wssBaseUrl: WSS_BASE_URL});
// sdk.rbac.fetchGroupPermissions({}) return object
[
{
id: '322f3070-826c-4dad-ba53-75fbfeee',
name: 'peaq-permission-2',
enabled: true
}
]
import { Sdk } from "@peaq-network/sdk";
const WSS_BASE_URL = "wss://quicknode1.peaq.xyz";
const SUBSTRATE_ADDRESS = process.env["SUBSTRATE_ADDRESS"];
const SUBSTRATE_SEED = process.env["SUBSTRATE_SEED"];
const sdk = await Sdk.createInstance({
baseUrl: WSS_BASE_URL,
chainType: Sdk.ChainType.SUBSTRATE,
seed: SUBSTRATE_SEED
});
// 1. Create a permission
const permissionName = "peaq-permission-2";
const txPermission = await sdk.rbac.createPermission({permissionName: permissionName});
// 2. Create a role
const roleName = "peaq-role-2";
const txRole = await sdk.rbac.createRole({roleName: roleName});
// 3. Assign permission to role
const p2rResp = await sdk.rbac.assignPermissionToRole({permissionId: txPermission.permissionId, roleId: txRole.roleId});
// 4. Create group
const groupName = "peaq-group-2";
const txGroup = await sdk.rbac.createGroup({groupName: groupName});
// 5. Assign role to group
const r2gResp = await sdk.rbac.assignRoleToGroup({groupId: txGroup.groupId, roleId: txRole.roleId});
// 6. Fetch group permissions
const response = await sdk.rbac.fetchGroupPermissions({owner: SUBSTRATE_ADDRESS, groupId: txGroup.groupId});
// disconnect when finished
await sdk.disconnect();
// sdk.rbac.fetchGroupPermissions({}) return object
[
{
id: '158a1097-3ba4-4cae-b682-c58e7a4a',
name: 'peaq-permission-2',
enabled: true
}
]

