5

I've been trying to create a crowd sale contract but it does not compile and comes with the error "unused local variable". Really not sure what to do as the code came directly from the ethereum crowd sale guide. enter image description here

4 Answers4

1

Try this instead:

interface ERC20I {
    function transfer(address _recipient, uint256 _amount) public returns (bool);
}

contract Crowdsale {
    ERC20I public tokenInterface;
    function Crowdsale(address _tokenAddress) {
        tokenInterface = ERC20I(_tokenAddress);
    }
}

Then whenever you want to transfer funds use this code: require(tokenInterface.transfer(recipient, amount));

hextet
  • 1,583
  • 7
  • 28
0

you can just ignore this warning or if you want to get rid of it you could use the following declaration:

contract token { function transfer(address , uint ){  } }

instead of

function transfer(address receiver, uint amount){  }
Badr Bellaj
  • 18,780
  • 4
  • 58
  • 75
0

Perhaps you are not using amount field when trying to send token rewards? Can you paste full code of the contract here, or share it through ethfiddle.io?

I have done some basic crowd funding contract development within Blockgeek's course. Maybe you can use the template I have picked up from there: https://ethfiddle.com/TN9MtiBVKq

In general, Ethfiddle is a good place to compile your code, and see errors popping up. Mist is really not the best place to check your code.

David
  • 49
  • 4
-1

The warning is there because you are not using the two variables which is being passed in transfer function.

You are passing two variables address receiver and uint amount to transfer function and the function is empty.

contract token {
    function transfer(address receiver, uint amount) {
        //...
        //use the parameters here to avoid the warning.
    }
}
Abhishek
  • 800
  • 4
  • 15