Ganache CLI Mining Simulation – Properly Simulate Mining Time

contract-developmentganachetestingtestrpc

I am using the Ganache CLI for testing my smart contracts and frontends. I need a way to incorporate a delay into ganache-cli when performing write transactions in order for it to more closely resemble the mainnet

I read that I should use the -b or --blockTime flag, however whenever launching ganache-cli with -b 15 my write transactions are still mined instantly.

Can anyone suggest the proper approach here?

Thanks!

Best Answer

Your approach is the good one as far as i know. I've been using this option and it always worked.

However note that having a 15 seconds block doesn't mean that when you send your transaction it will be mined in 15 seconds, sometimes it will be less.

e.g : as last block was mined 9 seconds ago, next block should be mined in 6 seconds and chain receives a transaction, your transaction will be then executed in 6 seconds, even if option has been set to 15 seconds.

Have you tried chaining multiple transactions ?

If you still state that your transactions are computed instantly maybe you should open an issue on the ganache-cli repo, giving the information related to your environment, versions, etc.

Related Topic