Alternative Method to Bypass the tx.origin Change in OpenZeppelin Contracts: Use _transferOwnership in Use Hello in the Main Constructor
#18
Closed
defido
started this conversation in
Show and tell
Replies: 2 comments
-
|
Instead of import "@openzeppelin/contracts/access/AccessControl.sol";contract XXX is ERC20, AccessControl {
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");Change constructor() ERC20("XXX", "XXX") {
_grantRole(DEFAULT_ADMIN_ROLE, tx.origin);
_grantRole(MINTER_ROLE, tx.origin);
_mint(tx.origin, 1000 * 10 ** decimals());To make sure only addresses that are in function mint(address to, uint256 amount) public onlyRole(MINTER_ROLE) {
_mint(to, amount); |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Please note that OpenZeppelin Contracts version 5.0.0 has made the initial |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This is OpenZeppelin (OZ)
Ownable-specific. If you're using your own access control setup, then feel free to ignore this.The current process using OZ's
Ownablein combination with thexdeployeris the following: themsg.senderof the contract creation transaction is the helper smart contractCreate2Deployerwith address0x13b0D85CcB8bf860b6b79AF3029fCA081AE9beF2. This in turn means using the standard OZOwnableaccess control method would set theownerto0x13b0D85CcB8bf860b6b79AF3029fCA081AE9beF2. One of the workarounds would be to change themsg.sendertotx.originin the original OZOwnablecontract. However, there exists a further way to resolve this problem: When using OZ contracts, simply use_transferOwnership(your wallet address)in the main constructor setup. This adjustment will trigger first a transfer of ownership to the helper contract and thereafter a transfer of the ownership from the helper smart contract to the wallet address you set in the main constructor (2 events will be emitted); everything within the same contract creation transaction. See also a more comprehensive discussion here.Beta Was this translation helpful? Give feedback.
All reactions