0

I have the following code of a simple openzeppelin ERC721:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract MyToken is ERC721 {
    constructor() ERC721("MyToken", "MTK") {}
}

If I remove the constructor, I get a missing implementation error. My question is, where do I in ERC721.sol that I need to implement a constructor? Like in other languages when its e.g. marked as abstract.

3

1 Answer 1

1

Read more about constructor inheritance chaining here. In the parent contract (ERC721), the constructor requires arguments (name_, symbol_). That's why you have to pass the arguments in your constructor. If the parent contract doesn't have contructor or has constructor without input argument, you don't have to specify your constructor.

In your code, if you don't want to write a constructor, you can do this with the same effect:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "@openzeppelin/contracts/token/ERC721/ERC721.sol";

contract MyToken is ERC721("MyToken", "MTK") {
 // dont need constructor
}

Your Answer

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

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