addMinter
/**
* Add minter function: Grant the 'minter' role to an address
* @param {string} publicAddress the address to be elevated at 'minter' role
* @notice Warning: This method will consume gas (30000 gas estimated)
* @returns {Promise<ethers.providers.TransactionResponse>} Transaction
*/
async addMinter({ publicAddress, gas = null }) {
if (!this.#contractDeployed && !this.contractAddress) {
// throw new Error('[ERC721Mintable.addMinter]');
throw new Error(
errorLogger({
location: ERROR_LOG.location.ERC721Mintable_addMinter,
message: ERROR_LOG.message.contract_not_deployed_or_loaded,
}),
);
}
if (!publicAddress || !ethers.utils.isAddress(publicAddress)) {
// throw new Error(
// '[ERC721Mintable.addMinter] A valid address is required to add the minter role.',
// );
throw new Error(
errorLogger({
location: ERROR_LOG.location.ERC721Mintable_addMinter,
message: ERROR_LOG.message.invalid_public_address,
}),
);
}
try {
const options = this.#addGasPriceToOptions({}, gas);
return await this.#contractDeployed.grantRole(this.MINTER_ROLE, publicAddress, options);
} catch (error) {
const { message, type } = networkErrorHandler(error);
// throw new Error(`${type}[ERC721Mintable.addMinter] An error occured: ${message}`);
throw new Error(
errorLogger({
location: ERROR_LOG.location.ERC721Mintable_addMinter,
message: ERROR_LOG.message.an_error_occured,
options: `${type} ${message}`,
}),
);
}
}
Copy link