0

I'm trying to understand why this very simple contract returns the error should be marked as abstract.

I don't have this error when I don't inherit from ERC721Enumerable.

pragma solidity ^0.8.0;

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

contract testERC721Enumerable is ERC721Enumerable {

  uint256 _test;

  constructor(uint256 test_) {
    _test = test_;
  }
}

I think it's because my constructor doesn't call something from ERC721Enumerable, but I'm pretty sure I've seen "neutral" constructors in contracts that inherits from something so it might be something else.

1 Answer 1

2

Since the ERC721Enumerable.sol is an ERC721 you need to feed the ERC721 constructor as well. You do that by calling that constructor inside yours. The following code does compile

pragma solidity ^0.8.0;

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

contract testERC721Enumerable is ERC721Enumerable {

  uint256 _test;

  constructor(uint256 test_, string memory name_, string memory symbol_) ERC721(name_, symbol_) {
    _test = test_;
  }
}

You could also just hardcode the name and symbol in the constructor like this:

  constructor(uint256 test_) ERC721("TokenName", "TokenSymbol") {
    _test = test_;
  }

The 'neutral' constructors you are talking about happen because the contract that they inherit don't have a constructor or that constructor does not require any arguments.

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.