0

Having a small issue, and unfortunately Google is of no help. Have three interlinked contracts I need to deploy at the same time -- one factory, and two ERC721 contracts.

Using Truffle, and deploying one contract after the other works fine. Then within the constructor of the factory, I have for example:

constructor(address finalNftAddress) {

    initialNftAddress = address(
        new InitialItem(finalAddress)
    );
}

Then within migration, I deploy the FinalItem contract along with the factory contract. That works fine, and all three contracts get created.

Issue is, I can't have two deployments within the migration and instead can only have one deployment and both ERC721 tokens created within constructor. Reason being, I need the full hex code of that contract so I can allow my clients to deploy via MetaMask keeping their private key secure, hence can't be passing a dynamically generated address into the constructor as an argument like I'm doing now.

When I try this though, it always throws an error. No valid error message given except that deployment failed, and to check constructors. For example:

constructor() {

    finalNftAddress = address(new FinalItem());
    initialNftAddress = address(
        new InitialItem(finalAddress)
    );
}

That simply won't work. What am I doing wrong, and is there anyway to instantiate two contracts within a constructor? Why is there a limit of only one like that?

2
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Mar 20, 2022 at 9:06
  • I don't know, wasn't able to resolve this. Something to do with the ERC721Tradable abstract class, and the _safeMint() call within the mintTo() function. Also, isApprovedForAll() function within that abstract class seems to play a role. It's really weird, and can't see anything within ERC721.sol. Compiling two ERC721 work fine, but when you flip one to ERC721Tradable it's compile error due to constructor with no valuable logs. Hell with it though, I'm done. We can just do a two stage deployment, as I'm not screwing around with this anymore. That will work just fine.
    – Matt Dizak
    Mar 21, 2022 at 0:48

1 Answer 1

0

There is no limit, you can instantiate as many contracts as you want (within the gas limits).

I'm guessing there is something wrong with the actual instantiated contract code - for example check the FinalItem constructor for issues. Furthermore, it's probably easier if you don't cast the contracts as address - just store the references like: finalNftAddress = new FinalItem(); where the type of finalNftAddress should be FinalItem.

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.