0

The error is:

browser/ballot.sol:54:2: ParserError: Function, variable, struct or modifier declaration expected.

}

The code of my token:

pragma solidity ^0.4.19;

interface Token{
   function transfer(address _receiver, uint256 _amount);
}

  contract MyFirstSafeICO{

 uint public buyPrice;

 Token public token;

 function MyFirstSafeICO(Token _token) {

    token = _token;  
    buyPrice = 1000;
}

 function() payable {

     _buy( msg.sender, msg.value);
 }

 function buy() payable returns (uint ){

  uint tokens = _buy(msg.sender, msg.value);
  return tokens;
}

 function buy(address _sender, uint256 _amount) internal returns (uint){

 uint tokens = _amount/buyPrice;

  token.transfer( _sender, tokens);

  return tokens;
}
0

Syntax 2 error's,

  1. _buy() definition not found
  2. didn't closed contract.

I am attaching modified code: pragma solidity ^0.4.19;

interface Token{
   function transfer(address _receiver, uint256 _amount);
}

  contract MyFirstSafeICO{

 uint public buyPrice;

 Token public token;

 function MyFirstSafeICO(Token _token) {

    token = _token;  
    buyPrice = 1000;
}

 function() payable {

     _buy( msg.sender, msg.value);
 }

 function buy() payable returns (uint ){

  uint tokens = _buy(msg.sender, msg.value);
  return tokens;
}

 function _buy(address _sender, uint256 _amount) internal returns (uint){

 uint tokens = _amount/buyPrice;

  token.transfer( _sender, tokens);

  return tokens;
 }
}
1

That error is because you're missing a closing curly brace at the very end of your code.

Then you'll see errors because you're trying to call a function called _buy, but you don't have any function with that name. You do, however have two functions named buy. I think you probably meant the second one to be named _buy, so just change its name.

At that point, the code compiles.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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