npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

web3-plugin-multicall

v0.0.2

Published

Multicall plugin to extend web3.js

Downloads

118

Readme

Web3.js Multicall Plugin

This is a web3.js 4.x plugin for interacting with Multicall contracts.

Prerequisites

Installation

yarn add web3-plugin-multicall

Using this plugin

Installing Version 4.x of web3

When adding the web3 package to your project, make sure to use version 4.x:

To verify you have the correct web3 version installed, after adding the package to your project (the above commands), look at the versions listed in your project's package.json under the dependencies section, it should contain version 4.x similar to:

"dependencies": {
	"web3": "4.0.3"
}

Registering the Plugin with a web3.js Instance

After importing MulticallPlugin from web3-plugin-multicall and Web3 from web3, register an instance of ChainlinkPlugin with an instance of Web3 like so:

import { MulticallPlugin } from 'web3-plugin-multicall';
import { Web3 } from 'web3';

const web3 = new Web3('YOUR_PROVIDER_URL');
const multicallPlugin = new MulticallPlugin();

web3.registerPlugin(multicallPlugin);

More information about registering web3.js plugins can be found here.

Please, note that the default address is set to 0xcA11bde05977b3631167028862bE2a173976CA11, as specified here.

You might however want to change it when using testnets, for example:

const MULTICALL_ADDRESS = '0xcA11bde05977b3631167028862bE2a173976CA11';
const multicallPlugin = new MulticallPlugin(MULTICALL_ADDRESS);

Plugin Methods

Multicall

This one is a game-changer. It lets you call multiple methods in one go using the Multicall contract.

makeMulticall

makeMulticall(methods: Methods, params?: MulticallConfig): Promise<MethodResults>;

Let's see it in action:

const web3 = new Web3(new HttpProvider(RPC_URL));
web3.registerPlugin(new MulticallPlugin());

const contract = new web3.eth.Contract(poolAbi, poolAddress);

const [tickSpacing, fee, liquidity, slot0] = await web3.multicall.makeMulticall([
  contract.methods.tickSpacing(), 
  contract.methods.fee(), 
  contract.methods.liquidity(), 
  contract.methods.slot0()
]);

You can even use it with multiple contracts. Imagine calling methods from different contracts in one shot:

const web3 = new Web3(new HttpProvider(RPC_URL));
web3.registerPlugin(new MulticallPlugin());

const pool1 = new web3.eth.Contract(poolAbi1, poolAddress1);
const pool2 = new web3.eth.Contract(poolAbi2, poolAddress2);

const [tickSpacing1, tickSpacing2] = await web3.multicall.makeMulticall([
  pool1.methods.tickSpacing(),
  pool2.methods.tickSpacing(),
]);

NOTE: Contracts have to be created using web3 instance that has the plugin registered, so the following example won't work:

import { Contract, Web3 } from 'web3';
import { MulticallPlugin } from 'web3-plugin-multicall';
const web3 = new Web3();
web3.registerPlugin(new MulticallPlugin());
// This is not the correct way to create a contract
const contract = new Contract(abi, address);
// This won't work
await web3.multicall.makeMulticall([contract.methods.method1(), contract.methods.method2()]);