OpenZeppelin ReentrancyGuard Constructor

I am trying to use the openzeppelin ReentrancyGuard contract within my ERC721 Token smart contract. Since this ReentrancyGuard contract has a constructor, from my understanding I am required to declare it in my contract. However, since I am already declaring the constructor for my ERC721 Token, I am receiving an error, stating “More than one constructor defined” if I try to declare them separately.

 contract MyContract is ERC721, ReentrancyGuard {
    constructor() ERC721("MyToken", "TOK") public {
    }
    constructor () ReentrancyGuard() internal {
    }
 }

Another solution would be to declare them together at once, as below:

 constructor() ERC721("MyToken", "TOK") ReentrancyGuard() public {
 }

However, in theory MyContract should be public, while the ReentrancyGuard one should be Internal. If I declare them both as above, both will be public. Is this an issue? Is there a better solution?

Thank you. J

1 Like

Hi @JF0001,

We don’t need to explicitly call the ReentrancyGuard constructor.

We just need to inherit from ReentrancyGuard and then use the modifiers. See: https://docs.openzeppelin.com/contracts/3.x/api/utils#ReentrancyGuard

2 Likes

Great! Thank you again @abcoathup

1 Like