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
import { Sdk } from "@peaq-network/sdk";
const HTTPS_BASE_URL = "https://quicknode.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://quicknode.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' }
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
import { Sdk } from "@peaq-network/sdk";
const HTTPS_BASE_URL = "https://quicknode.peaq.xyz";
const WSS_BASE_URL = "wss://quicknode.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://quicknode.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)
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
import { Sdk } from "@peaq-network/sdk";
const HTTPS_BASE_URL = "https://quicknode.peaq.xyz";
const WSS_BASE_URL = "wss://quicknode.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://quicknode.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. |
| 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://quicknode.peaq.xyz";
const WSS_BASE_URL = "wss://quicknode.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'
}
// sendEvmTx({}) return object
TransactionReceipt {
provider: JsonRpcProvider {},
to: '0x0000000000000000000000000000000000000802',
from: '0x9Eeab1aCcb1A701aEfAB00F3b8a275a39646641C',
contractAddress: null,
hash: '0x5653326390b5277aad0e326eb9ecfe0a90bdef323c4e50c29be4a679044d3a30',
index: 0,
blockHash: '0xf95e4b31c28a23b6aff89d15411c9e36c833ec226ab3ced54325439124899458',
blockNumber: 4501640,
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000001000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000100000000000000',
gasUsed: 35429n,
blobGasUsed: null,
cumulativeGasUsed: 35429n,
gasPrice: 100000000000n,
blobGasPrice: null,
type: 2,
status: 1,
root: undefined
}
import { Sdk } from "@peaq-network/sdk";
const WSS_BASE_URL = "wss://quicknode.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.fetchPermission({}) return object
{
message: 'Successfully update permission 77395752-8588-47c5-8bd5-0d2bf273 with new name: peaq-permission-new'
}
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
import { Sdk } from "@peaq-network/sdk";
const HTTPS_BASE_URL = "https://quicknode.peaq.xyz";
const WSS_BASE_URL = "wss://quicknode.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'
}
// sendEvmTx({}) return object
TransactionReceipt {
provider: JsonRpcProvider {},
to: '0x0000000000000000000000000000000000000802',
from: '0x9Eeab1aCcb1A701aEfAB00F3b8a275a39646641C',
contractAddress: null,
hash: '0xb63e38df51375830ad61be4afa89b512a812375a0f84800c765821f82176f800',
index: 1,
blockHash: '0x13c29ec81311aad9dfce89630938885e1ca4f3f0b8a8fb81526072ba8fb05dc4',
blockNumber: 4502232,
logsBloom: '0x00000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000000000000020000000000000020000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
gasUsed: 34682n,
blobGasUsed: null,
cumulativeGasUsed: 78842n,
gasPrice: 100000000000n,
blobGasPrice: null,
type: 2,
status: 1,
root: undefined
}
import { Sdk } from "@peaq-network/sdk";
const WSS_BASE_URL = "wss://quicknode.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)
This function allows you 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
import { Sdk } from "@peaq-network/sdk";
const HTTPS_BASE_URL = "https://quicknode.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'
}
// sendEvmTx({}) return object
TransactionReceipt {
provider: JsonRpcProvider {},
to: '0x0000000000000000000000000000000000000802',
from: '0x9Eeab1aCcb1A701aEfAB00F3b8a275a39646641C',
contractAddress: null,
hash: '0xb3c8a7b2127754ef031cd3469afdec0aca6c8736e4b29373c9ad49a171a652c1',
index: 2,
blockHash: '0x2281ba090e6e1449ed5c5f0bd3ddff6231a4bf1782546a19cc1e0d7bcaa50eeb',
blockNumber: 4501755,
logsBloom: '0x00000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000400000000020000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
gasUsed: 31342n,
blobGasUsed: null,
cumulativeGasUsed: 73342n,
gasPrice: 100000000000n,
blobGasPrice: null,
type: 2,
status: 1,
root: undefined
}
import { Sdk } from "@peaq-network/sdk";
const WSS_BASE_URL = "wss://quicknode.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)
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
import { Sdk } from "@peaq-network/sdk";
const HTTPS_BASE_URL = "https://quicknode.peaq.xyz";
const WSS_BASE_URL = "wss://quicknode.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://quicknode.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)
This function allows you 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
import { Sdk } from "@peaq-network/sdk";
const HTTPS_BASE_URL = "https://quicknode.peaq.xyz";
const WSS_BASE_URL = "wss://quicknode.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'
}
// sendEvmTx({}) return object
TransactionReceipt {
provider: JsonRpcProvider {},
to: '0x0000000000000000000000000000000000000802',
from: '0x9Eeab1aCcb1A701aEfAB00F3b8a275a39646641C',
contractAddress: null,
hash: '0x55678a0cbbbb5089acdaa15427b21879270d985f2bb82aaea331f5316d3ef566',
index: 1,
blockHash: '0x5cce714cf1c11ed6f65680458bf989e69b3749fa0b0b85124176119ae6cc1ea9',
blockNumber: 4501891,
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000001000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000',
gasUsed: 29178n,
blobGasUsed: null,
cumulativeGasUsed: 68884n,
gasPrice: 100000000000n,
blobGasPrice: null,
type: 2,
status: 1,
root: undefined
}
import { Sdk } from "@peaq-network/sdk";
const WSS_BASE_URL = "wss://quicknode.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'
}
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. |
- 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://quicknode.peaq.xyz";
const WSS_BASE_URL = "wss://quicknode.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://quicknode.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://quicknode.peaq.xyz";
const WSS_BASE_URL = "wss://quicknode.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://quicknode.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
}
]

