1

I am deploying a Crowdsale contract locally, using truffle and ganache.

The problem is, that the MintableToken is created during the deployment of the Crowdsale contract, using the createTokenContract() function.

Having just the 4 transactions in Ganache (see image below), it's not clear to me which address the Token Address is - I assume none of them, because it is an internal transaction?!

However, when I use the test network (Ropsten) I can inspect the internal transactions using etherscan, and find the MintableToken address.

How can I do this locally with ganache? If that's not possible with Ganache, is there another way to circumvent this locally/ inspect the internal transactions/ print them? Any other solution besides of decoupling createTokenContract from the Contact creation?

enter image description here

2 Answers 2

1

One option would be to call the token address function of the crowdsale contract.

if you crowdsale.sol contract has the following line (as it does by default) you could get the address by calling the deployed crowdsale function.

MintableToken public token;

Although this is only possible depending on what modifications you have made to the base contracts.

1

Internal transactions are not visible via Web3 API and they leave no trace in blocks. Proper way for internal transaction to make some information visible is to emit an event like this:

contract Foo {
}

contract Bar {
  event FooCreation (Foo indexed foo);

  function createFoo () public returns (Foo) {
    Foo foo = new Foo ();
    emit FooCreation (foo);
    return foo;
  }
}

Then you may use Web3 API to query such events.

Also, as @ryanh mentioned in his answer, in case you need to create another contract only once in constructor, you may use public property to expose address of created contract:

contract Foo {
}

contract Bar {
  Foo public foo;

  constructor () public {
    foo = new Foo ();
  }
}
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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