Skip to content

Commit

Permalink
Add grant role
Browse files Browse the repository at this point in the history
  • Loading branch information
cheran-senthil committed Jun 11, 2024
1 parent 9d17825 commit 843c8fc
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/commands/admin/grantrole.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Arg } from "@oclif/core/lib/interfaces";
import { ethers } from "ethers";
import { TransactionCommand } from "../../base";
import { getSigner, parseAddress, pretty, run } from "../../helpers";

export default class GrantRole extends TransactionCommand {
static summary = "Grant a role to an account on the Armada Network.";
static examples = [
"<%= config.bin %> <%= command.id %> RECONCILER_ROLE 0x0000000000000000000000000000000000000000 0xContractAddress",
];
static usage = "<%= command.id %> ROLE ACCOUNT CONTRACT_ADDRESS";
static args: Arg[] = [
{ name: "ROLE", description: "The role to grant.", required: true },
{ name: "ACCOUNT", description: "The address to grant the role to.", required: true },
{ name: "CONTRACT_ADDRESS", description: "The address of the contract.", required: true },
];

public async run(): Promise<unknown> {
const { args, flags } = await this.parse(GrantRole);

const signer = await getSigner(flags.network, flags.rpc, flags.address, flags.signer, flags.key, flags.account);
const abi = ["function grantRole(bytes32 role, address account) external"];
const contract = new ethers.Contract(args.CONTRACT_ADDRESS, abi, signer);

const role = ethers.utils.id(args.ROLE);
const account = parseAddress(args.ACCOUNT);

try {
const tx = await contract.populateTransaction.grantRole(role, account);
const output = await run(tx, signer, [contract]);
this.log(pretty(output));
return output;
} catch (e) {
this.error(`Error granting role`);
}
}
}

0 comments on commit 843c8fc

Please sign in to comment.