My current setup has a contract which inherits the AccessControl. The contract is not necessarily deployed prior to me calling various functions on it, so l line up a bunch of function calls prior to deployment using the ethers.js encodeFunctionData
. One function, grantRole, I call like so:
const ABI = (await deployments.getArtifact("StableToken")).abi;
const iface = new ethers.utils.Interface(ABI);
calldatas.push(
iface.encodeFunctionData("grantRole", [
"0x9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6",
issuance.address
])
);
The role I'm granting is called MINTER_ROLE and it is declared in the solidity contract like so:
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
and, once the StableToken contract is deployed, I can call it in JS with:
await stableToken.MINTER_ROLE()
As can be seen, the role is hardcoded. Instead, I'm wondering if there is a way to call stableToken.MINTER_ROLE()
using encodeFunctionData (or some other method) and then passing it to the grantRole call, something like:
const ABI = (await deployments.getArtifact("StableToken")).abi;
const iface = new ethers.utils.Interface(ABI);
const role = iface.encodeFunctionData("MINTER_ROLE");
calldatas.push(
iface.encodeFunctionData("grantRole", [
role,
issuance.address
])
);
Not that the above works, but the idea would be that MINTER_ROLE() could be encoded and then the calls result could be passed to the grantRole function.
Is this even possible? If so, how to I get the first encoded function data into the second encoded function data? I'm using the propose method available in OpenZeppelin's Governor, with the calls lined up in calldata.