The ERC721 standard contract requires a token name and symbol in its constructor. I have inheritance pattern that looks likes Contract A is B and Contract B is ERC721.

If I want to set my token name and symbol dynamically on deployment, do I have to raise the constructor argument through each stage (from A's constructor to B's constructor to ERC721's constructor) or can I raise directly from A to ERC721? If yes, how?

Currently I'm passing through each parent like so

pragma solidity 0.6.8;

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

contract B is ERC721 {

    constructor(string memory _name, string memory _symbol) ERC721(_name, _symbol) public {}

contract A is B {

    constructor(string memory _name, string memory _symbol) B(_name, _symbol) public {}
  • 2
    The implementation looks fine. You've to pass on the constructor arguments of the parent contract, for them to instantiate any variable that might be necessary with its contract function references.
    – Tirtha
    May 20 '20 at 11:47
  • My concern is I have 7 such intermediary contracts between contract A and ERC721, and for each one I instantiate a constructor for the sole purpose of passing down the parameters to ERC721. Feels extremely inefficient / bad practice May 21 '20 at 4:18
  • 1
    Do all the previous 7 contracts need to extend ERC 721? If not why not do something like contract A is B, ERC721{ constructor(string memory _name, string memory _symbo, _othersl) B(_others) ERC721(_name, _symbol) public {} }
    – Tirtha
    May 21 '20 at 6:27
  • yep the ERC721 contract is to the root of all other contracts May 21 '20 at 7:06
  • 1
    As name and symbol are set in the constructor of ERC721 then you need to pass them down. I would look to see if you could restructure any of the 7 contracts so that they don't have to all inherit from ERC721 and you can use multiple inheritance. If you have questions on using OpenZeppelin you can also ask in the Community Forum: forum.openzeppelin.com Disclosure: I am the Community Manager at OpenZeppelin.
    – abcoathup
    May 21 '20 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.