How to change rate/price of a token in Crowdsale?

So, I am trying to write a sale contract which increases the price or modifies the rate of a crowdsale after each purchase(when buyTokens is called). I was going to implement it with a state variable the adds (+1) each time when buyTokens is called. And writing a custom buy method. But, I just realized that there is no method to change rate. Or is it and I miissed it? Can someone help me on this?

1 Like

Yeah, if you want to change the rate, you need to add it by yourself.

1 Like

Yes, but I am currently struggling to get the rate in my contract. How am I suppose to access it and modify it? It’s a private variable

1 Like

Maybe you can have a look at this doc: https://docs.openzeppelin.com/contracts/2.x/crowdsales#crowdsale-rate

2 Likes

Hi @PradhumnaPancholi,

There is an IncreasingPriceCrowdsale in OpenZeppelin Contracts 2.x that you could use for inspiration.

I put together an example of manually setting a crowdsale rate using this. :warning: This code has not been tested or audited. Please appropriately test and audit before using in production.
Setting crowdsale rate manually

1 Like