Created
April 28, 2021 13:10
-
-
Save wivern-co-uk/e3e2d3435c02766b0bd36947b89f4865 to your computer and use it in GitHub Desktop.
Batch RPC calls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| updatePrices() { | |
| const batch = new web3.eth.BatchRequest() | |
| this.pairs = [] | |
| const requests = []; | |
| serializedPairs.forEach(lp => { | |
| requests.push(new Promise((resolve, reject) => { | |
| const contract = new web3.eth.Contract(pancakePairAbis, lp.pair.address) | |
| batch.add(contract.methods.getReserves().call.request((error, reserves) => { | |
| this.requestCount++ | |
| if (error) return reject(error) | |
| this.pairs.push( | |
| this.newPairFromSerializedPairAndReserves(lp, reserves) | |
| ) | |
| resolve(reserves); | |
| })) | |
| })) | |
| }); | |
| batch.execute() | |
| return Promise.all(requests); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment