1

I am trying to use the openzeppelin ReentrancyGuard contract within my ERC721 Token smart contract. Since this ReentrancyGuard contract has a constructor, 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". How can I solve this issue?

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

Thank you. J

1 Answer 1

3

You can add it to the original constructor:

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

With that said, I do not believe OpenZeppelin's ReentrancyGuard has a constructor. You may want to verify that.

3
  • 1
    Actually Shane, I had another question if I may. In theory MyContract should be public, while the ReentrancyGuard one should be Internal. If I declare them both as you suggested, both will be public. Not sure if this could be an issue. (Forgot to mention that ReentrancyGuard does have a constructor.)
    – JF0001
    Mar 5, 2021 at 3:36
  • Can you provide a link to the ReentrancyGuard code? Mar 5, 2021 at 5:03
  • 1
    Actually, although there is a constructor, one does not need to call it. Thanks again.
    – JF0001
    Mar 5, 2021 at 13:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.