0

I'm writing a token sale smart contract & my original error was my function had the same name as the contract and I changed it to a constructor because the contract cant have the same name as the function. I know get this error

browser/ballot_test.sol:11:17: ParserError: Expected '(' but got identifier
constructor ChampToken(ChampTokenSale _tokenContract, uint256 _tokenPrice) public {
^--------^

Here is my code -

constructor ChampTokenSale(ChampTokenSale _tokenContract, uint256 _tokenPrice) 
 public {
        admin = msg.sender;
        tokenContract = _tokenContract;
        tokenPrice = _tokenPrice;
    }
  • If you are creating a crowdsale you may want to look at OpenZeppelin Contracts to see if this meets your needs. See the documentation for details: docs.openzeppelin.com/contracts/2.x/crowdsales If you have questions on using OpenZeppelin you can ask in the Community Forum: forum.openzeppelin.com Disclosure: I am the Community Manager at OpenZeppelin – abcoathup Aug 15 at 8:28
  • 1
    Thanks I will look at the docs, much appreciated – Sakhr Aug 19 at 13:24
1

The constructor doesn't take a name.

Change your code to:

constructor (ChampTokenSale _tokenContract, uint256 _tokenPrice) public { 
    admin = msg.sender; 
    tokenContract = _tokenContract; 
    tokenPrice = _tokenPrice; 
}

(See "Creating Contracts" in the docs.)

  • Thank you this was helpful – Sakhr Aug 19 at 13:23

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.