run

The run method is used to execute the set of actions required to grant a role to specific addresses within a market. This method is typically used after generating the necessary actions with the getActions method. It handles the entire process of sending the necessary transactions and completing the role assignment, making it a critical component of the Role SDK.

In the context of the Role SDK, this method will:

  1. Send a transaction to the blockchain to grant a specified role to a list of addresses.
  2. Register the role assignment with the backend API to ensure the setup is reflected in the system.

The run method handles these steps seamlessly, ensuring that both on-chain and off-chain components are correctly updated.

Parameters

IGrantRoleRequest: An object containing the configuration for the role assignment. This includes:

  • chainId: number: The ID of the blockchain network where the transaction will be sent.
  • marketId: number: The ID of the market where the role is being granted.
  • roleId: number: The ID of the role that is being assigned.
  • addresses: string[]: An array of wallet addresses to which the role will be granted.

Returns

Promise<IGrantRoleOutput> - A promise that resolves to the result of the actions execution, including transaction details and the updated context. It includes details of the executed actions, such as transaction information, the assigned role, and any relevant metadata.

Usage Example

// Step 1: Fetch all available roles
const roles = await sdk.rolesService.getRoles();
console.log('Available roles:', roles);

// Step 2: Fetch a specific role by ID
const role = await rolesService.getRoleById(1);
console.log('Role details:', role);

// Step 3: Assign a role to multiple addresses
const roleAssignRequest = {
  roleId: role.id,
  marketId: 123,
  addresses: ["0x1234...5678", "0xabcd...efgh"],
};

await rolesService.assignRole(roleAssignRequest);
console.log('Role assigned successfully.');

// Step 5: Use Grant Role Actions to assign roles on-chain and register them
const grantRole = sdk.grantRole;
const actions = grantRole.getActions();

actions.on('nextAction', (state) => {
  console.log('Current action state:', state);
});

const grantRoleRequest = {
  chainId: 1,
  marketId: 123,
  roleId: role.id,
  addresses: ["0x1234...5678"],
};

const result = await actions.run(grantRoleRequest);
console.log('Role granted on-chain and registered:', result);