Skip to Content
Ethereum Cookbook
book

Ethereum Cookbook

by Manoj P R
August 2018
Intermediate to advanced
404 pages
11h 19m
English
Packt Publishing
Content preview from Ethereum Cookbook

How to do it...

Here are the steps that must be followed to batch requests using web3.js:

  1. Creating and executing batch requests is different between versions of web3.js. If you are using web3.js v0.2x.x, use the following method to create a batch:
var batch = web3.createBatch();
  1. Now, add as many requests as you want to the queue:
var balance = web3.eth.getBalance.request(    web3.eth.accounts[1],     'latest',     callback);var contract = web3.eth.Contract(abi)    .at(address)    .balance    .request(web3.eth.accounts[0], callback2)batch.add(balance); batch.add(contract);
  1. Once all requests are queued up, start executing them with the execute method:
batch.execute();
  1. The execution of batches works slightly different in the upcoming version of web3.js ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Building Ethereum Dapps

Building Ethereum Dapps

Roberto Infante
Ethereum For Dummies

Ethereum For Dummies

Michael G. Solomon

Publisher Resources

ISBN: 9781789133998Supplemental Content