I'm currently coding a crowdsale for school in which the fictious participants can buy a token. During the first round the participants would also get a second token which would act as a governance token.

Inside my crowdsale constructor I'm deploying the two tokens as so:

function Crowdsale() public {
    price = 1 ether;
    wallet = msg.sender;
    dollar = new StandardToken("Dollar", "HWD", 2, 2000000);
    vote = new StandardToken("Vote", "HWV", 2, 500000);
    StandardToken(dollar).transfer(wallet, 500000);

When deploying the contract on Ropsten with injected Web3 through Remix everything works fine. I can easily test this by calling this function on the crowdsale contract, which should return 1 500 000 (since we sent 500kto sender at creation)

function tokensAvailable() public view returns (uint256) {
    return StandardToken(dollar).balanceOf(this);

call to Crowdsale.tokensAvailable
[call] from:0xba5116fea48692a505c5e2a898d4c803f0ca5d2a, to:Crowdsale.tokensAvailable(), data:60659...59a92, return: 
      "0": "uint256: 1500000"

However when deploying through the JavascriptVM I can only call the functions for the second token created, never the first. The methods for the first token always return Undefined.

Is this because Remix can't handle multiple tokens in memory or what would be the case here? I worked on this project 2 weeks ago and I could swear everything worked properly. (My memory could be abandoning me here though).

Any ideas?

Thank you !

  • What types are dollar and vote? If they are of type StandardToken then you don't have to cast dollar in the tokensAvailable() function to a StandardToken first. Eg you could replace the line in tokensAvailable() with return dollar.balanceOf(this)
    – willjgriff
    Jan 23, 2018 at 1:22

1 Answer 1


Is your process something similar to this?

enter image description here

Check that the correct token is selected before clicking 'At Address' and that the address represents that contract. I get the issue you're describing when I put an incorrect address into the 'Load contract from Address' field.

  • at first I thought it was human error on my part but It's the same procedure for Ropsten and there it does work. Also I have a function in my crowdsale contract directly referring to the token that ends up being undefined so even when not using that procedure I get the error. "Cannot read property length of undefined ... " Jan 22, 2018 at 22:43
  • How do you reference the token contract that is undefined through the Crowdsale contract? Does your Crowdsale contract call functions on it directly or do you get the address of the token and create an interface to it through Remix with the process above or something else entirely?
    – willjgriff
    Jan 23, 2018 at 0:40

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.