Repeating transactions hangs - web3js local geth

0 votes

I have an issue with transactions on my local ethereum network - at some point, transaction hangs & spends a lot of ETH from my account.

Here's a sample code:

async function send(toAccount, weiVal) {
  let account = await w3.getDefAccount();

  for (let i = 0; i < 100; i++) {
    let res = await web3.eth.sendTransaction({
      from: account,
      to: toAccount,
      value: weiVal
    });
    await helper.timeout(2000);
  }
}

send('0x5648...', 100000000000000);

It hangs at sendTransaction call (promise is never resolved) on some random iteration.

Sep 24, 2018 in Blockchain by slayer
• 29,370 points
1,029 views

1 answer to this question.

0 votes

If you are sending transactions back-to-back from the same account, you need to manually set the nonce, because the node will not keep track of it correctly.

Example code

async function send(toAccount, weiVal) {
  const account = await web3.getDefAccount();
  // the transaction count does not include *pending* transactions
  // but is a good starting point for the nonce
  const nonce = await web3.eth.getTransactionCount(account);

  let promises =  [];
  for (let i = 0; i < 100; i++) {
    promises.push(web3.eth.sendTransaction({
      from: account,
      to: toAccount,
      nonce: nonce++, // increment the nonce for every transaction
      value: weiVal
    }));
  }

  return Promise.all(promises);
}

await send('0x5648...', 100000000000000);
answered Sep 24, 2018 by digger
• 26,740 points

Related Questions In Blockchain

0 votes
1 answer

How to make Geth transactions faster?

You can change the speed by the ...READ MORE

answered Jul 17, 2018 in Blockchain by slayer
• 29,370 points
1,693 views
0 votes
1 answer

How to make sure transactions take no fee in a private Ethereum blockchain?

In a private ethereum network you have ...READ MORE

answered Mar 26, 2018 in Blockchain by Christine
• 15,790 points

edited Mar 26, 2018 by Christine 1,567 views
+1 vote
2 answers

Is there any relation between the number of transactions processes and the miners?

the direct answer to your query is ...READ MORE

answered Jun 19, 2018 in Blockchain by Perry
• 17,100 points
808 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,923 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,451 views
+1 vote
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,460 points
1,427 views
0 votes
1 answer

How i can use nodejs to watch transactions in bitcoin network?

you can use  const Socket = require('blockchain.info/Socket'); const mySocket ...READ MORE

answered Jul 9, 2018 in Blockchain by digger
• 26,740 points
1,282 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP