# Grant/Revoke Roles

## **Introduction**

There is a common role flow in inverter network, this guide guides you on how to manage granting / revoking and checking different roles throughout our protocol.

## **Setup Requirements**

The guide includes code snippets for Inverter Network's TypeScript SDK. Please refer to the relevant code snippets based on the SDK you are using.

1. **Set up Inverter Network SDK**: Refer to the Quick Start guides for detailed instructions. See the [React SDK Guide](/sdk/react-sdk.md) or [TypeScript SDK Guide](/sdk/typescript-sdk.md) for more information.
2. **Deploy a Workflow**: Refer to the Deploy a Workflow guide for detailed instructions. See the [React SDK Guide ](/sdk/react-sdk/deploy-a-workflow.md)or [TypeScript SDK Guide](/sdk/typescript-sdk/deploy-a-workflow.md) for more information.
3. **Retrieve a deployed Workflow**: Refer to the Operate a Workflow guide for detailed instructions. See the [React SDK Guide](/sdk/react-sdk/operate-a-workflow.md) or [TypeScript SDK Guide](/sdk/typescript-sdk/operate-a-workflow.md) for more information.

* **Optionally if your setup needs a specific contract**: Refer to the Deploy a Contract Guide for detailed instructions. See the [React SDK](/sdk/react-sdk/deploy-a-contract.md) Guide or [TypeScript SDK](/sdk/typescript-sdk/deploy-a-contract.md) Guide for more information.

## Retrieve Workflow Args

The chosen modules for the workflows should be specified for type safety.

{% code overflow="wrap" %}

```typescript
import type { RequestedModules } from '@inverter-network/sdk'

// Should either be `as const` or be passed dirrectly in the `requestedModules` param
const requestedModules = {
    fundingManager: 'FM_DepositVault_v1',
    paymentProcessor: 'PP_Simple_v1',
    authorizer: 'AUT_Roles_v1',
    optionalModules: [
        'LM_PC_Bounties_v1'
    ]
} as const satisfies RequestedModules
```

{% endcode %}

## Fetch Role Hexes

To begin with the process we need the role hexes from the authorizer.

{% code overflow="wrap" %}

```typescript
const adminRole = await workflow.authorizer.read.getAdminRole.run()

const verifierRole = await workflow.optionalModule.LM_PC_Bounties_v1.read.VERIFIER_ROLE.run()
```

{% endcode %}

## Admin Role

### Check Role

For checking the status of the role we need to use the role hex.

```typescript
const hasAdminRole = await workflow.authorizer.read.hasRole.run([
    adminRole,
    walletClient.account.address,
])
```

### Grant or Revoke Role

For admin roles we need to use the `grantRole` or `revokeRole` function from the authorizer.

{% code overflow="wrap" %}

```typescript
const args = [
    adminRole,
    walletClient.account.address,
] as const

// Grant role
const grantTransactionHash = await workflow.authorizer.write.grantRole.run(args)

// Revoke role
const revokeTransactionHash = await workflow.authorizer.write.revokeRole.run(args)
```

{% endcode %}

## Module Role

For any role which is not a `orchestrator` admin role we need to generate a role id using the `authorizer` this generation is necessary to have a unique identifier since every workflow has different modules with different addresses.

### Generate Role

Note that this is only to check the status of a module role.

{% code overflow="wrap" %}

```typescript
const generatedVerifierRole = await workflow.authorizer.read.generateRoleId.run([
    workflow.optionalModule.LM_PC_Bounties_v1.address,
    verifierRole,
])
```

{% endcode %}

### Check Role

For checking the status of the role we need to use the generated role.

{% code overflow="wrap" %}

```typescript
const hasVerifierRole = await workflow.authorizer.read.hasRole.run([
    generatedVerifierRole,
    walletClient.account.address,
])
```

{% endcode %}

### Grant or Revoke Role

For module roles we need to use the `grantModuleRole` or `revokeModuleRole` function from the module itself not the authorizer function.

For the granting or revoking we are using the non generated role.

{% code overflow="wrap" %}

```typescript
const args = [
    verifierRole,
    walletClient.account.address,
] as const

// Grant role
const grantTransactionHash = await workflow.optionalModule.LM_PC_Bounties_v1.write.grantModuleRole.run(args)

// Revoke role
const revokeTransactionHash = await workflow.optionalModule.LM_PC_Bounties_v1.write.revokeModuleRole.run(args)
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.inverter.network/sdk/guides/grant-revoke-roles.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
