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:


for( var i=0;i<10;i++){
    //wait for 10 seconds

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


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
    @Ismael sorry for that. The updated answer should work fine. – Roman Frolov Apr 16 '18 at 19:54

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, privacy policy and cookie policy

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