New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

ethers-batch-request

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ethers-batch-request

Using Batch Request Queries in ethers.

latest
Source
npmnpm
Version
0.0.5
Version published
Maintainers
1
Created
Source

ethers-batch-request

HTTP batch request is a feature most Ethereum clients support, for example, Geth. With batch requests enabled, multiple HTTP requests can be packaged into one single request and sent to the server. Server process this bulk request and returns a bulk result. All of these are done in a single round trip.

This feature can be useful for reducing the load on the server and improving the performance to a certain extent.

15 measurements were averaged, which shows the performance of batch request > Multicall > normal request. Compared with sending single requests in parallel, batch request reduces 38% of the total request time, and multicall reduces 18% of the total request time.

Data source: HTTP batch request VS multicall contract

ethers-batch-request will automatically process the queue and return the correct value:

# with pnpm
pnpm add ethers-batch-request

# with yarn
yarn add ethers-batch-request
import { BatchContract } from 'ethers-batch-request'
import { providers } from 'ethers'

// BatchContract works the same way as ethers' Contract
const provider = new providers.JsonRpcProvider('https://...')
const contract = new BatchContract('0x...', interface, provider)

// BatchContract will automatically package into an HTTP request
// When there are no new queries, it sends a batch request and returns all the values
const owners = await Promise.all([
  contract.ownerOf(0),
  contract.ownerOf(1),
  contract.ownerOf(2),
  contract.ownerOf(3),
  contract.ownerOf(4),
  contract.ownerOf(5),
])

Currently, batch querying is only supported for the Contract.

Precautions

Requests in a batch request are executed in order, which means if a new block is received during execution, the subsequent results are likely to be different.

Both batch request and multicall contract return multiple results in a single response. Both of them require much more computational resources. They can easily trigger “request timeout” errors and “response size too big” errors, which makes them not suitable for complex calls.

License

MIT License © 2023-PRESENT Hairyf

Keywords

ethers

FAQs

Package last updated on 04 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts