0

Well I have contract which creates another contract:

contractA{    
    function myMethod(address contractbAddress) payable public{
        address contractcAddress = (new contractC).value(msg.value)(msg.sender,address(this),contractbAddress);
        contractB(contractbAddress).setContract(msg.sender,contractcAddress); 
        confirmEvent(msg.sender,contractcAddress);
    }
}
contractB{
    function setContract(address sender,address contractcAddress){
        ....
    }
}
contractC{
    function contractC(address sender,address contractaAddress,address contractbAddress){
        ....
    }
}

I have contractB's address and contractA's address when I deployed them using truffle migrate.

Now when I will call function myMethod using web3, how will it get to know what is contractC because they no longer have the source code of it?

1 Answer 1

0

I'd assume your function myMethod is creating contract C and not B, ie (new contractC) instead.

Since you are generating an event with the address you want

confirmEvent(msg.sender,contractcAddress);

You can listen for that event

contractA.events.confirmEvent.watch((err, ev) => {
    console.log(ev); // contract c address is a parameter of the event
});

Another option is to request the receipt of the transaction that calls myMethod the event should be between the logs of the receipt.

2
  • Yea myMethod is creating creating contract, I will edit that part. But the problem is call to myMethod is always unsuccessful because the deployed contractA doesn't know what contractC is.
    – shubh0906
    Commented May 8, 2018 at 11:52
  • For contractA to be able to create contractC you need to import the file where contractC is defined. If that is a problem you can use the factory pattern.
    – Ismael
    Commented May 9, 2018 at 1:43

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.