I am writing ERC20 based smart contract using solidity. I want to specify the amount on which user can actually buy my coin. I had tested my smart contract on ropsten test network and it shows 0.00$ as my coin price.

My questions are:

  1. Is it possible to set the initial coin price while deploying smart contract? If yes, code snippet or some url are welcomed. If no, Please explain how to set coin price?

  2. Is there any way to increase the coin price such that if my 25% coins are sold the price will be set to (2 x current price).

I am a newbie to ERC20 and solidity. Any help/comment would be appreciated.


You set a variable that define the price and set the value in the constructor:

contract My contract{
    uint256 public TokenPrice;

    constructor(uint256 _price){
        TokenPrice = price;


Then you use this variable to calculate the number of tokens you will give per Ether. There is a full example of how to do this in Ethereum website.

Hope this helps

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.