0
function transfer(address to, uint tokens) public returns (bool success) ;
     uint256 public max_contribution = 50 ether; 
    uint256 public min_contribution = 0.1 ether; 
    require (msg.value >= min_contribution);
    require (msg.value <= max_contribution);
    balances[msg.sender] = safeSub(balances[msg.sender], tokens);
    balances[to] = safeAdd(balances[to], tokens);
    emit Transfer(msg.sender, to, tokens);
    return true;
}

ParserError: Expected identifier, got 'LParen' require (msg.value >= min_contribution);

Which identifier should i put after "require"?

1

A couple of things are wrong with this function.

  1. The signature ends with a ;, where a { should be
  2. variables inside functions cannot be public. Public fields should be declared outside the function, for example at the beginning of the contract.
  3. If you want to use msg.value, you need to declare the function as payable

Actually, the lines with require are correct for as far as I can tell

End result:

uint256 public max_contribution = 50 ether; 
uint256 public min_contribution = 0.1 ether; 

function transfer(address to, uint tokens) public payable returns (bool success) {
    require(msg.value >= min_contribution);
    require(msg.value <= max_contribution);
    balances[msg.sender] = safeSub(balances[msg.sender], tokens);
    balances[to] = safeAdd(balances[to], tokens);
    emit Transfer(msg.sender, to, tokens);
    return true;
}
  • May be i should put uint256 commands somewhere else, but min_contribution is not working. I`ve sent 0.01 and still got tokens. – Daniel Apr 24 '18 at 13:26
  • Can you tell me what this function needs to do exactly? For example: what is a contribution in this context? – Henk Apr 24 '18 at 14:41
  • I`ve just needed min. contribution size: for example if someone sents less than a 0.1 eth, he get no tokens and recieve ether back. – Daniel Apr 24 '18 at 14:57
  • There must be something else that is wrong in your situation. This function seems to work like it should for me – Henk Apr 25 '18 at 8:23
  • yes, it is working when i am testing it in remix. But after i deploy the contract and send amount of eth that is lower than min_contribution to contract adress, i still recieve tokens – Daniel Apr 25 '18 at 11:24

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.