getActions

The getActions method prepares and returns a set of actions required to perform specific operations, such as granting roles within a specific market. This method returns an object containing actions that involve interacting with the blockchain and the backend API. Specifically, it facilitates the creation and execution of a transaction to grant a role, as well as the registration of role assignment metadata with the backend.

The getActions method generates an object containing a series of actions (IActionsSet) that need to be performed for a given operation. These actions might involve transactions, API calls, or other steps required to complete the process. The returned object includes two crucial methods:

  • run: Executes the generated actions, typically sending transactions to the blockchain and performing other necessary operations.
  • on: Allows subscription to the execution state of the actions, enabling you to monitor progress, handle errors, or update your UI accordingly.

Parameters

abortController?: AbortController (optional): An optional AbortController that can be used to cancel the execution of the actions if necessary.

Returns

IGrantRoleActions - A set of actions (IActionsSet).

IActionsSet: An object containing the set of actions to be executed. This object includes:

  • run(marketConfig: IMarketDeployConfig): A method to execute the actions. It executes the role-granting transaction on the blockchain and registers the role assignment.
  • on(event: string, callback: (data: any) => void): A method to subscribe to the events during the execution of the actions, such as success, error, or other custom events.

Usage Example

// Call getActions to generate the actions required for granting a role
const actions = sdk.rolesService.getActions();

// Step 3: Optionally, subscribe to the execution state to track progress
actions.on('state', (state) => {
  console.log('Current state:', state);
});

// Step 4: Prepare the configuration for the role grant
const roleGrantConfig = {
  chainId: 1, // Ethereum mainnet
  marketId: 123, // Market ID where the role will be granted
  roleId: 456, // ID of the role to be granted
  addresses: ["0x1234...5678"], // List of addresses to grant the role to
};

// Step 5: Execute the actions
try {
  const result = await actions.run(roleGrantConfig);
  console.log('Role granted successfully:', result);
} catch (error) {
  console.error('Error during role grant:', error);
}