How to update the crowdsale rate?

So, I have asked the same question before but I got stuck on something and it lead to more confusion. What was doing was adding “1000000000000000” to the rate to increase price by 0.001 ETH. But I realized that it doesn’t work like that. So, I did the math and found a different solution, that was to subtract 0.0014 from rate. Now, solidity has no way to handle decimals. How can I approach this ? Can rates be in decimal values?

1 Like

I am not sure what do you mean exactly, but I think if you want to increase the price of each purchase, you can change the rate like so:

contract CrowdSale {
    uint256 buyRate = 1e18;
    mapping(address => uint256) public _balance;

    function buyTokens() payable public {
        uint256 buyAmount = msg.value * 1e18 / buyRate;
        // TODO: buyAmount should be valid
        _balance[msg.sender] += buyAmount;
        buyRate += 0.0001e18;
    }
}

So just like above, cause this is no decimals in the contract, so if you want to do it, you have got to multiply firstly, then divide, 1000 * 9 / 10 => 1000 * 0.9

2 Likes

I am not sure if I follow. Can you give an example? is it possible to just increase price by 0.001 Eth on each purchase? Or are u talking about rate (asking to make sure on rate vs price)? Also, what is that 0.001e18? Does it meant 0.001 with 10^18 as in literally 0.001 eth? If that’s it than it will solve a big problem for me.

P.S :- sorry for so many questions

1 Like

is it possible to just increase price by 0.001 Eth on each purchase?

Yes, at least, I think so, cause in my demo, I increase the price by the buyRate, so when buyRate is 1e18, it means 1 eth = 1 token, and when buyRate is equal to 1.001e18, it means 1.001 eth = 1 token, so the price increased.

Also, what is that 0.001e18? Does it meant 0.001 with 10^18 as in literally 0.001 eth?

Yeah, 0.001e18 is equal to 0.001eth.

1 Like