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?
Yeah, if you want to change the rate, you need to add it by yourself.
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
Maybe you can have a look at this doc: https://docs.openzeppelin.com/contracts/2.x/crowdsales#crowdsale-rate
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. This code has not been tested or audited. Please appropriately test and audit before using in production.
Setting crowdsale rate manually