mine.js 961 B

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. This script advances Ganache network state. It runs as a sidecar pod alongside the devnet and
  3. ensures that manual token transfers triggered through the web UI will be able to be confirmed.
  4. */
  5. advanceBlock = () => {
  6. return new Promise((resolve, reject) => {
  7. web3.currentProvider.send({
  8. jsonrpc: "2.0",
  9. method: "evm_mine",
  10. id: new Date().getTime()
  11. }, (err, result) => {
  12. if (err) {
  13. return reject(err);
  14. }
  15. const newBlockHash = web3.eth.getBlock('latest').hash;
  16. return resolve(newBlockHash)
  17. });
  18. });
  19. }
  20. function sleep(ms) {
  21. return new Promise(resolve => setTimeout(resolve, ms));
  22. }
  23. module.exports = function(callback) {
  24. const fn = async () => {
  25. while (true) {
  26. console.log(await advanceBlock());
  27. await sleep(1000);
  28. }
  29. }
  30. fn().catch(reason => console.error(reason))
  31. }