Git Product home page Git Product logo

ext-provider-multicall's Introduction

Ethers: MulticallProvider

The MulticallProvider is designed to reduce the latency and large number of calls that can occur, especially on the initial loading of page.

This does not require any multicall contract be deployed to the network, and does not deploy any multicall contract to the network. It is only designed to assist in read-only call operations, and does not currently support sending multicall transactions.

For inspiration, see:

Installing

/home/ricmoo> npm install @ethers-ext/provider-multicall

Usage

import { MulticallProvider } from "@ethers-ext/provider-multicall";

// Create the provider which will serve as the main transport
const provider = new InfuraProvider();

// Crate the multicall provider, which will aggregate calls
const multicaller = new MulticallProvider(provider);

// Connect your contracts to the multicaller
const dai = new Contract("dai.tokens.ethers.eth, daiAbi, multicaller);

// Make your multicalls
const [ sym, name, totalSupply ] = await Promise.all([
  dai.symbol(),
  dai.name(),
  dai.totalSupply(),
]);

API

new MulticallProvider(provider)

Create a new MulticallProvider using provider as the transport.

provider.queueCall(to, data) => Promise<Array<{ status: boolean, data: string }>>

Place a call into the queue to be called on the next drain. Any normal provider.call will call this internally.

provider.drainCallQueue() => Promise<Array<{ status: boolean, data: string }>>

Regardless of the remaining time before the drainInterval, trigger all calls. This must be called explicitly when using manual drain (i.e. the drainInterval is -1).

provider.drainInterval

The drainInterval (by default, 10ms) specifies the interval to aggregate calls within. If the drainInterval is set to 0, then only calls made within a single event loop will be aggregated and if -1 is used then the provider.drainCallQueue MUST be called manually.

Pay special attention when using manual a drainInterval, as it can easily lead to deadlock, if a response is await-ed without another execution in the event loop to trigger a drain.

Contributing

If the multicall contract is changed (./contracts/multicall.sol), then you must call npm run build-solc before the changes will be added to the ./src.ts/_contract.ts file, which is a TypeScript version of the ABI and bytecode, generated using ./src.ts/_build.ts.

Please open a discussion before making any changes. :o).

Notes

This is designed for Ethers v6. For Ethers v5, see the old Multicaller.

License

MIT License.

ext-provider-multicall's People

Contributors

ricmoo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.