Hello OpenZeppelin Community,
I am facing issues executing the approve
and transfer
methods in my custom ERC20 smart contract. I have configured the appropriate roles in the AccessManager
(passed as initialAuthority
to the constructor of my contract), but the methods still revert with an AccessManagerUnauthorized
error.
Here is the code for my ERC20 contract:
// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/manager/AccessManaged.sol";
contract MyPumpkinToken is ERC20, AccessManaged {
constructor(address initialAuthority)
ERC20("MyPumpToken", "MPTK")
AccessManaged(initialAuthority)
{}
function mint(address to, uint256 amount) public restricted {
_mint(to, amount);
}
function transfer(address recipient, uint256 amount) public override restricted returns (bool) {
return super.transfer(recipient, amount);
}
function approve(address spender, uint256 value) public override restricted returns (bool) {
address owner = _msgSender();
_approve(owner, spender, value);
return true;
}
}
I have followed these steps:
- Deploy
AccessManager
Contract: TheAccessManager
contract is deployed correctly. - Deploy
MyPumpkinToken
Contract: TheMyPumpkinToken
contract is deployed with theAccessManager
as theinitialAuthority
. - Grant Role: I granted the required role (role ID
3
) to the account trying to call the functions. - Set Function Selector: I set the function selectors for
approve
andtransfer
to be restricted by role ID3
.
However, despite setting these configurations, the approve
and transfer
methods are not executing as expected. Below is a screenshot of the error message I am encountering:
Can anyone help identify what might be going wrong or provide guidance on resolving this issue?
Thank you for your assistance!