Python SDK provides support for creating and managing roles in the peaq network’s Role-Based Access Control (RBAC) system.

create_role(role_name, role_id)

Creates a new role in the peaq network’s Role-Based Access Control (RBAC) system. The role will be owned by the address derived from the seed (if provided) or must be signed externally.

ParameterTypeEVMSubstrateDescription
role_namestringRequiredRequiredName of the role to be created.
role_idstringOptionalOptionalUnique identifier for the role (32 characters). If not provided, one will be auto-generated.

Create Role Code Examples

import os
from dotenv import load_dotenv
from peaq_sdk import Sdk
from peaq_sdk.types import ChainType

load_dotenv()

HTTPS_PEAQ_URL = os.getenv("HTTPS_PEAQ_URL")

sdk = Sdk.create_instance(
    base_url=HTTPS_PEAQ_URL,
    chain_type=ChainType.EVM
)

role_name = "test_role_1"

response = sdk.rbac.create_role(role_name=role_name)

fetch_role(owner, role_id)

Fetches a specific role by its ID and owner address from the peaq network’s RBAC system.

ParameterTypeEVMSubstrateDescription
ownerstringRequiredRequiredAddress representing the owner of the role.
role_idstringRequiredRequiredUnique identifier of the role to fetch (32 characters).

Fetch Role Code Examples

import os
from dotenv import load_dotenv
from peaq_sdk import Sdk
from peaq_sdk.types import ChainType

load_dotenv()

HTTPS_PEAQ_URL = os.getenv("HTTPS_PEAQ_URL")
EVM_ADDRESS = os.getenv("EVM_ADDRESS")

sdk = Sdk.create_instance(
    base_url=HTTPS_PEAQ_URL,
    chain_type=ChainType.EVM
)

role_id = "afd2ae0e-b1db-42b9-bca1-93e9328b"

response = sdk.rbac.fetch_role(owner=EVM_ADDRESS, role_id=role_id)

fetch_roles(owner)

Fetches all roles associated with the specified owner address from the peaq network’s RBAC system.

ParameterTypeEVMSubstrateDescription
ownerstringRequiredRequiredAddress that represents the owner of all the fetched roles.

Fetch Roles Code Examples

import os
from dotenv import load_dotenv
from peaq_sdk import Sdk
from peaq_sdk.types import ChainType

load_dotenv()

HTTPS_PEAQ_URL = os.getenv("HTTPS_PEAQ_URL")
EVM_ADDRESS = os.getenv("EVM_ADDRESS")

sdk = Sdk.create_instance(
    base_url=HTTPS_PEAQ_URL,
    chain_type=ChainType.EVM
)

response = sdk.rbac.fetch_roles(owner=EVM_ADDRESS)

update_role(role_id, role_name)

Updates the name of an existing role in the peaq network’s RBAC system.

ParameterTypeEVMSubstrateDescription
role_idstrRequiredRequiredUnique identifier of the role to update (32 characters).
role_namestrRequiredRequiredNew name to assign to the role.

Update Role Code Examples

import os
from dotenv import load_dotenv
from peaq_sdk import Sdk
from peaq_sdk.types import ChainType

load_dotenv()

HTTPS_PEAQ_URL = os.getenv("HTTPS_PEAQ_URL")

sdk = Sdk.create_instance(
    base_url=HTTPS_PEAQ_URL,
    chain_type=ChainType.EVM
)

role_id = "0bb60413-ebdd-44fb-ab2c-e7e0714f"
new_role_name = "updated-peaq-role"

response = sdk.rbac.update_role(
    role_id=role_id,
    role_name=new_role_name
)

disable_role(role_id)

Disables a role in the peaq network’s RBAC system, making it inactive while preserving its data.

ParameterTypeEVMSubstrateDescription
role_idstrRequiredRequiredUnique identifier of the role to disable (32 characters).

Disable Role Code Examples

import os
from dotenv import load_dotenv
from peaq_sdk import Sdk
from peaq_sdk.types import ChainType

load_dotenv()

HTTPS_PEAQ_URL = os.getenv("HTTPS_PEAQ_URL")

sdk = Sdk.create_instance(
    base_url=HTTPS_PEAQ_URL,
    chain_type=ChainType.EVM
)

role_id = "0bb60413-ebdd-44fb-ab2c-e7e0714f"

response = sdk.rbac.disable_role(role_id=role_id)

assign_role_to_user(role_id, user_id)

Assigns a specific role to a user in the peaq network’s RBAC system.

ParameterTypeEVMSubstrateDescription
role_idstrRequiredRequiredUnique identifier of the role to assign (32 characters).
user_idstrRequiredRequiredUnique identifier of the user to assign the role to (32 characters).

Assign Role to User Code Examples

import os
from dotenv import load_dotenv
from peaq_sdk import Sdk
from peaq_sdk.types import ChainType

load_dotenv()

HTTPS_PEAQ_URL = os.getenv("HTTPS_PEAQ_URL")

sdk = Sdk.create_instance(
    base_url=HTTPS_PEAQ_URL,
    chain_type=ChainType.EVM
)

role_id = "0bb60413-ebdd-44fb-ab2c-e7e0714f"
user_id = "9e8c7866-8435-4b76-8683-709a03c9"

response = sdk.rbac.assign_role_to_user(role_id=role_id, user_id=user_id)

fetch_user_roles(owner, user_id)

Fetches all roles assigned to a specific user in the peaq network’s RBAC system.

ParameterTypeEVMSubstrateDescription
ownerstrRequiredRequiredAddress representing the owner of the roles.
user_idstrRequiredRequiredUnique identifier of the user to fetch roles for (32 characters).

Fetch User Roles Code Examples

import os
from dotenv import load_dotenv
from peaq_sdk import Sdk
from peaq_sdk.types import ChainType

load_dotenv()

HTTPS_PEAQ_URL = os.getenv("HTTPS_PEAQ_URL")
EVM_ADDRESS = os.getenv("EVM_ADDRESS")

sdk = Sdk.create_instance(
    base_url=HTTPS_PEAQ_URL,
    chain_type=ChainType.EVM
)

user_id = "9e8c7866-8435-4b76-8683-709a03c9"

response = sdk.rbac.fetch_user_roles(owner=EVM_ADDRESS, user_id=user_id)

unassign_role_to_user(role_id, user_id)

Removes a role assignment from a user in the peaq network’s RBAC system.

ParameterTypeEVMSubstrateDescription
role_idstrRequiredRequiredUnique identifier of the role to unassign (32 characters).
user_idstrRequiredRequiredUnique identifier of the user to remove the role from (32 characters).

Unassign Role from User Code Examples

import os
from dotenv import load_dotenv
from peaq_sdk import Sdk
from peaq_sdk.types import ChainType

load_dotenv()

HTTPS_PEAQ_URL = os.getenv("HTTPS_PEAQ_URL")

sdk = Sdk.create_instance(
    base_url=HTTPS_PEAQ_URL,
    chain_type=ChainType.EVM
)

role_id = "0bb60413-ebdd-44fb-ab2c-e7e0714f"
user_id = "9e8c7866-8435-4b76-8683-709a03c9"

response = sdk.rbac.unassign_role_to_user(
    role_id=role_id,
    user_id=user_id
)