5

web3.BatchRequest(); does it produce a single transaction with several functions of the (possibly different) contracts or not?

  var batch = new web3.BatchRequest();
  batch.add(web3.eth.sendSignedTransaction.request(raw3, (err,tx3Hash) =>{
  console.log('err:', err, 'tx3Hash:', tx3Hash)  
  }))
  batch.add(web3.eth.sendSignedTransaction.request(raw4, (err,tx4Hash) =>{
  console.log('err:', err, 'tx4Hash:', tx4Hash)  
  }))
  batch.execute()

this code gives me two different transactions, how i can have them in one?

1 Answer 1

11

BatchRequest batches only JSON-RPC calls for your Ethereum node API. Transactions are independent and separate concern of those. BatchRequest only saves you some modest amount of HTTP traffic.

3
  • 1
    Thanks! I have only 15 rep and cant upvote your answer. Jan 26, 2021 at 12:26
  • Can BatchRequest save gas fee? thanks. Apr 22, 2022 at 6:49
  • 1
    BatchRequest does not save gas. Apr 22, 2022 at 9:37

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.