I built out a fairly complex contract factory and I noticed the factory was only creating instances of itself, not the "child" contract. After observing this I figured I was doing something wrong so I scaled back and tried to implement a super basic version first. However, I'm still observing the same behavior. I wrote this in the Remix IDE and deployed it on the Javascript VM environment.

Here is my factory:

pragma solidity ^0.4.21;

contract ExampleContract {
    string public Name;

    function ExampleContract (string name) public {
        Name = name;

contract Factory {
    address[] public contracts;

    function createContract(string name) public returns(address)  {
        address newContract = new ExampleContract(name);
        return newContract;

Everything compiles and deploys fine. When I use the createContract function it deploys a new instance of the Factory contract. Am I missing something?



  • I can't reproduce this behavior. I deployed Factory, then I called createContract("test"). Then I called contracts(0) to get the address of the new contract. I chose ExampleContract from the dropdown, pasted the address next to "At Address" and then clicked "At Address." I then had an instance of ExampleContract, and calling Name() on it correctly returned the string "test" (as I originally supplied to createContract). – user19510 Mar 17 '18 at 22:10
  • hey @smarx thanks for the reply. I included a GIF into my question. can you confirm we are performing the same actions but getting different results? I switched over to a different machine/OS and was able to replicate my problem. – R X Mar 17 '18 at 22:26
  • You failed to pick the right contract from the dropdown before clicking "At Address." – user19510 Mar 17 '18 at 22:29
  • Ohhh. I was not aware you had to pick the contract from the drop down when using the At Address feature. Noob mistake. Seems obvious now. If you want to move your response to an actual answer I will mark it as correct. Thanks again! – R X Mar 17 '18 at 22:37

Per the comments above, the issue was that the wrong contract was chosen when clicking the "At Address" button.

Your Answer

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

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