0

I have a smart contract that is making two (a token and a crowdsale) other contracts.

mapping (uint => myStruct) myMapping;

function start(uint uuid) public returns (bool) {
    address tokenAddress = new Token();
    address crowdsaleAddress = new Crowdsale();
    Token(tokenAddress).addMinter(crowdsaleAddress);
    myMapping[uuid].addr_t = tokenAddress;
    myMapping[uuid].addr_c = crowdsaleAddress;
    return true;
}

The issue I'm running into is that this basically works some times. When I call it a few times in a row errors start to be thrown. It works the first time or the last time.

Are tokenAddress and crowdsaleAddress not being set by the time that they are being passed into Token(tokenAddress).addMinter(crowdsaleAddress).

I tried to debug this using truffle/remix debugger, but when contracts make other contracts, things get pretty crazy.

Is there anything wrong with this code? tokenAddress and crowdsaleAddress are address and not txhashes? Are tokenAddress and crowdsaleAddress valid immediately or do they take time to mine? I'm pretty confused about where the problem is so any help is appreciated.

3
  • Sounds like you need to change these two addresses from local variables to state variables. Commented Jan 4, 2019 at 9:37
  • Thanks for the tip. I googled that. That would sort of help to explain how it works at the start and end. Doesn't Token(tokenAddress).addMinter(crowdsaleAddress); save the address to the blockchain? Aren't tokenAddress and crowdsaleAddress supposed to be temporary?
    – Alexis
    Commented Jan 4, 2019 at 9:47
  • No, you don't need to use state variables. Local in-memory variables (as you have) are exactly what you want. Your code looks absolutely fine. If you want more help, please tell us what you mean by "errors start to be thrown."
    – user19510
    Commented Jan 4, 2019 at 9:58

0

Your Answer

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

Browse other questions tagged or ask your own question.