1

i want to send a transaction every 10 seconds and observer it in truffle. In the course there is described how to send a single transaction, but is there a way to send it every 10 seconds with help of a javascript?

Something like:

Greetings.deployed().then(function(instance){app=instance;})

for( var i=0;i<10;i++){
    //wait for 10 seconds
    app.increaseCount();
}

But how can i implement the waiting function and how can i call the script from powershell?

2 Answers 2

1

On test RPC just:

const delay = require("delay")

for(let i = 0; i < 10; i++) {
  await delay(10000).then(async () => {
      await instance.increaseCount({ from: account })
  })
  let i = await instance.i.call()
  console.log(new Date().getTime(), i.toNumber())
}

To do the same on the mainnet be sure to unlock your account before this loop with:

web3.eth.personal.unlockAccount(account, password, time_period)
1
  • 1
    @Ismael sorry for that. The updated answer should work fine. Apr 16, 2018 at 19:54
0

In addition to Roman's answer above, to run an external script in truffle, use :

truffle exec name-of-your-file.js --network name-of-your-network

In windows, you may have to use truffle.cmdinstead of truffle

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.