4

I need to send 0.1 ETH to 10 unique addresses from the same address at the same time. I am manually incrementing each transaction's nonce, and the transactions are sent successfully.

However, each transaction is entered into a new block. For example, transaction A in block 1, B in 2, C in 3, and so on. The problem is that this isn't scalable across n transactions, because I'd have to wait for n blocks to confirm.

Is there a proper way to batch-send ETH so that the collective of transactions confirms as quickly as possible?

Edit: This has only been tested on Kovan. Even with Kovan's 4 second block time, shouldn't transactions sent at the exact same time be included in the same block?

5
  • Yes, don't await for the transactions to complete. – goodvibration Apr 14 '20 at 4:45
  • I'm not. They're sent asynchronously at the exact same time. – slider Apr 14 '20 at 6:04
  • 1
    You might wanna share how exactly you submit those transactions (that is, if you're hoping to get an actual suggestion on how to change it to fit your goals). – goodvibration Apr 14 '20 at 6:14
  • 1
    It is literally called BatchRequest: web3js.readthedocs.io/en/v1.2.6/web3-eth.html#batchrequest. And you can never 100% guarantee to have all transactions in one block. It's up to the miner to decide which transactions to include. The only thing you can guarantee is the order by setting the nonce. – Markus - soliditydeveloper.com Apr 14 '20 at 8:33
  • @soliditydeveloper.com yeah, BatchRequest does the trick. Although, I can't get a transaction's confNumber from a web3.eth.sendSignedTransaction.request(), only the txHash from the callback. – slider Apr 14 '20 at 19:00
0

I have been playing around with a similar thing however, on the ropsten network and i get multiple transactions in the same block when testing with sending 100 transactions. I have written the following function that allows me to send an arbitrary amount of transactions to my smart contract at the same time. Perhaps this could be re-purposed for your needs?

async function multipleTx(n) {
  accounts = await web3.eth.getAccounts()
  for (let i = 0; i < n; i++) {
    instance.methods
      .addSubmission(i, i, i, i)
      .send({
        from: accounts[0],
        gasPrice: 10000000000,
      })
      .then((receipt) => {
        console.log(receipt)
      })
  }
}
0

All web3.eth.send() calls automatically increment nonce by your wallet (what wallet provider you are using for this?).

You can simply fire out as many web3.eth.send() calls or contract calls as possible and then await them as Promise.all() to resolve. Miners will fill your transactions in block and try to fit as many transactions, yours or otheres, in a block as possible.

11
  • Thanks. But this would only block my process from continuing until every single transaction has resolved. My question relates to sending the transactions, not receiving confirmations. – slider Apr 14 '20 at 17:16
  • web3.eth.send() returns something called PromiEvent. You can listen to event.on("txhash") to immediately go forward as soon as wallet has a txhash. Depending on the wallet logic this can be before of after the transaction has been broadcasted to the network. web3js.readthedocs.io/en/v1.2.0/… – Mikko Ohtamaa Apr 14 '20 at 18:16
  • I'm doing that. But I need to wait for x confirmations of each transaction, which doesn't help if they're sent in different blocks. – slider Apr 14 '20 at 18:56
  • Your last comment does not make sense. Each transaction has its own confirmation cycle. Just wait that all transactions have current block - mined block > needed confirmations. – Mikko Ohtamaa Apr 14 '20 at 23:17
  • Transactions that are in the same block are on the same confirmation cycle. This solution doesn't put transactions in the same block like BatchRequest does. It merely sends them out one at a time and waits for the very last tx to confirm before resolving the promise. – slider Apr 14 '20 at 23:20

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.