0

I'm trying out Batch Request provided by web3.js. In the example below I want to test making 300 transactions but i get the error log displayed below. I'm trying to figure out the error log but it seems to me that there is some kind of limit. Does anyone know if that is the case?

instance is just my contract instance.

async function multipleTx(
  TRANSACTIONS = 300,
  GAS_PRICE = 2000000000,
) {
  let accounts = await web3.eth.getAccounts()

  await instance.methods
    .addSubmissionNoCheck(6, Math.round(Date.now() / 1000))
    .send({
      from: accounts[0],
      gasPrice: GAS_PRICE,
    }) // works

  var bookingBatch = new web3.BatchRequest()
  for (let i = 0; i < TRANSACTIONS; i++) {
    bookingBatch.add(
      instance.methods
        .addSubmissionNoCheck(6, Math.round(Date.now() / 1000))
        .send.request(
          { from: accounts[i], gasPrice: GAS_PRICE, value: 1 },
          bookingCallback
        )
    )
  }
  bookingBatch.execute() //throws error
}
multipleTx()

Error Log:

Error: Invalid JSON RPC response: {}
    at Object.InvalidResponse (C:\Users\Diddi\Documents\mjukvaruteknik\examensar
bete\tqdt33\node_modules\web3-core-helpers\src\errors.js:42:16)
    at C:\Users\Diddi\Documents\mjukvaruteknik\examensarbete\tqdt33\node_modules
\web3-core-requestmanager\src\batch.js:61:60
    at Array.forEach (<anonymous>)
    at C:\Users\Diddi\Documents\mjukvaruteknik\examensarbete\tqdt33\node_modules
\web3-core-requestmanager\src\batch.js:54:12
    at C:\Users\Diddi\Documents\mjukvaruteknik\examensarbete\tqdt33\node_modules
\web3-core-requestmanager\src\index.js:166:20
    at C:\Users\Diddi\Documents\mjukvaruteknik\examensarbete\tqdt33\node_modules
\async\internal\map.js:32:9
    at C:\Users\Diddi\Documents\mjukvaruteknik\examensarbete\tqdt33\node_modules
\async\internal\once.js:12:16
    at iteratorCallback (C:\Users\Diddi\Documents\mjukvaruteknik\examensarbete\t
qdt33\node_modules\async\eachOf.js:58:13)
    at C:\Users\Diddi\Documents\mjukvaruteknik\examensarbete\tqdt33\node_modules
\async\internal\onlyOnce.js:12:16
    at C:\Users\Diddi\Documents\mjukvaruteknik\examensarbete\tqdt33\node_modules
\async\internal\map.js:29:13
    at C:\Users\Diddi\Documents\mjukvaruteknik\examensarbete\tqdt33\node_modules
\@truffle\hdwallet-provider\node_modules\web3-provider-engine\index.js:157:9
    at C:\Users\Diddi\Documents\mjukvaruteknik\examensarbete\tqdt33\node_modules
\async\internal\once.js:12:16
    at replenish (C:\Users\Diddi\Documents\mjukvaruteknik\examensarbete\tqdt33\n
ode_modules\async\internal\eachOfLimit.js:61:25)
    at C:\Users\Diddi\Documents\mjukvaruteknik\examensarbete\tqdt33\node_modules
\async\internal\eachOfLimit.js:71:9
    at eachLimit (C:\Users\Diddi\Documents\mjukvaruteknik\examensarbete\tqdt33\n
ode_modules\async\eachLimit.js:43:36)
    at C:\Users\Diddi\Documents\mjukvaruteknik\examensarbete\tqdt33\node_modules
\async\internal\doLimit.js:9:16

11
  • How and where do you call function multipleTx? Do you await for it to complete, or do you resolve the promise that it returns in any other manner? BTW, you probably wanna add return await before bookingBatch.execute(). May 7, 2020 at 9:18
  • I just called multipleTx from the bottom of the file. I can update my post to show that. I tried return await bookingBatch.execute() same error occurs
    – Conviley
    May 7, 2020 at 9:22
  • 2
    BTW, I'm pretty sure that BatchRequest is for RPCs (.call) only. You, on the other hand, are trying to use it for transactions (.send). May 7, 2020 at 10:17
  • 1
    @Conviley Batch requests will not help you with making hundred of transactions. A note for web3 v0.20 applies here Note Batch requests are not faster! In fact making many requests at once will in some cases be faster, as requests are processed asynchronously. Batch requests are mainly useful to ensure the serial processing of requests. github.com/ethereum/wiki/wiki/JavaScript-API#batch-requests
    – Ismael
    May 7, 2020 at 16:27
  • 1
    @Ismael Thanks for the link! Since I set up my own ethereum node i will be dropping trying to implement batch requests. The reason i want to test on ropsten is to get as close to mainnet performance as possible without actually testing on mainnet.
    – Conviley
    May 7, 2020 at 16:43

1 Answer 1

1

Web3js doesn't have the request limit, but the node, you communicate with, could have. Unfortunately, web3js@1.* doesn't give the errors thrown by the network or server in batch requests. I had a similar issue - the server has rate-limited my requests, but I didn't get a helpful message about the error. This issue seems not to be fixed in v1 - https://github.com/web3/web3.js/pull/5875

As a workaround, when the InvalidResponse error is returned for the BatchRequest, I switch to processing the requests by one with web3.currentProvider.send(singleItem, cb), in the callback I get the error from the server, where all required details on backoff are specified, and I can wait X time to continue with Requests.

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.