0

If I try to run the example given here: https://web3js.readthedocs.io/en/1.0/web3-eth.html#batchrequest

With the following code:

const batch = new web3.BatchRequest();
batch.add(web3.eth.getBalance.request('0x0000000000000000000000000000000000000000', 'latest'));

batch.execute()
.then(res => console.log(res))
.catch(err => console.log(err));

I get the error:

TypeError: method.callback is not a function

Does anybody have experience with this?

version: "web3": "^1.0.0-beta.55"

3
  • at what line are you getting this?
    – Sanjay S B
    Jul 2, 2019 at 5:19
  • Try 1.0.0-beta.34 instead. Jul 2, 2019 at 5:21
  • @SanjaySB at node_modules/web3-providers/dist/web3-providers.cjs.js:823:22 at Array.forEach (<anonymous>) at node_modules/web3-providers/dist/web3-providers.cjs.js:808:23 at process.internalTickCallback (internal/process/next_tick.js:77:7)
    – jasper
    Jul 2, 2019 at 8:58

1 Answer 1

4

For some reason (this is not documented anywhere I could find) the request method requires a callback function as a last parameter, as such:

const batch = new web3.BatchRequest();
batch.add(web3.eth.getBalance.request('0x0000000000000000000000000000000000000000', 'latest', (err, res) => console.log(err, res));

batch.execute()
.then(res => console.log(res))
.catch(err => console.log(err));
2
  • thanks, still not documented properly!
    – S--
    Sep 19, 2020 at 13:59
  • How do I apply a callback to a balanceOf function for an ERC20 token held by a particular wallet? First I add to the batch: batch.add(contract.methods.balanceOf(walletAddress).call.request({}, blockNumber, (err, res) => console.log(err, res))); Then I call it like this ``` await batch.execute() .then(res => batchRequest = res) .catch(err => console.log(err)); ``` But I get this error: TypeError: Cannot read properties of undefined (reading 'then') Mar 7, 2022 at 7:58

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.