βš‘πŸš€ Call multiple view functions, from multiple Smart Contracts, in a single RPC query!

Overview

ethers-multicall

npm package Build Status Downloads Issues Commitizen Friendly Semantic Release

⚑ πŸš€ Call multiple view functions, from multiple Smart Contracts, in a single RPC query!

Querying an RPC endpoint can be very costly (100+ queries) when loading data from multiple smart contracts. With multicall, batch these queries into a single, on-chain query, without additional over-head!

This is the standalone package of the library formerly created & used by Zapper.

Install

npm install @morpho-labs/ethers-multicall
yarn add @morpho-labs/ethers-multicall

Usage

import { ethers } from "ethers";

import { EthersMulticall } from "@morpho-labs/ethers-multicall";

const provider = new ethers.providers.JsonRpcBatchProvider("...");
// pass the chainId as option (second parameter, defaults to 1 = mainnet)
const multicall = new EthersMulticall(provider);

// if the chainId is unknown, defaults to the provider's network chainId
// const multicall = await EthersMulticall.new(provider)

// if you want to query with overrides (such as a blockTag), pass them as options:
// const multicall = new EthersMulticall(provider, { chainId, overrides: { blockTag } })
// or manually change them:
// multicall.overrides.blockTag = 14999999

const uni = multicall.wrap(
  new ethers.Contract("0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984", UniswapAbi)
); // make sure to always wrap contracts to benefit from multicalls

Promise.all([uni.name(), uni.symbol(), uni.decimals()]).then(console.log);
Comments
  • Benefit from a fallback in case of Multicall failure

    Benefit from a fallback in case of Multicall failure

    A multicall failure can happen when:

    • Multicall is not deployed on the chain queried
    • Multicall was not deployed at the blockTag queried
    • this list may not be exhaustive...

    So rather than failing, just propagate the call without the Multicall (this could be called Optimistic Multicall)

    This PR also updated to Multicall3 addresses for gas savings

    released 
    opened by Rubilmax 3
  • Add limitations to readme

    Add limitations to readme

    Description of change

    Pull-Request Checklist

    • [ ] Code is up-to-date with the main branch
    • [ ] npm run lint passes with this change
    • [ ] npm run test passes with this change
    • [ ] This pull request links relevant issues as Fixes #0000
    • [ ] There are new or updated unit tests validating the change
    • [ ] Documentation has been updated to reflect this change
    • [ ] The new commits follow conventions outlined in the conventional commit spec
    released 
    opened by Rubilmax 1
  • Add `defaultBlockTag` option

    Add `defaultBlockTag` option

    Feature Request

    Is your feature request related to a problem? Please describe.

    Describe the solution you'd like

    Describe alternatives you've considered

    Are you willing to resolve this issue by submitting a Pull Request?

    • [ ] Yes, I have the time, and I know how to start.
    • [ ] Yes, I have the time, but I don't know how to start. I would need guidance.
    • [ ] No, I don't have the time, although I believe I could do it if I had the time...
    • [ ] No, I don't have the time and I wouldn't even know how to start.
    released 
    opened by Rubilmax 1
  • The automated release is failing 🚨

    The automated release is failing 🚨

    :rotating_light: The automated release from the main branch failed. :rotating_light:

    I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

    You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can fix this πŸ’ͺ.

    Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

    Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main branch. You can also manually restart the failed CI job that runs semantic-release.

    If you are not sure how to resolve this, here are some links that can help you:

    If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


    No npm token specified.

    An npm token must be created and set in the NPM_TOKEN environment variable on your CI environment.

    Please make sure to create an npm token and to set it in the NPM_TOKEN environment variable on your CI environment. The token must allow to publish to the registry https://registry.npmjs.org/.


    Good luck with your project ✨

    Your semantic-release bot :package::rocket:

    semantic-release 
    opened by github-actions[bot] 0
  • Retry twice with each half payload if query failed because of payload too large

    Retry twice with each half payload if query failed because of payload too large

    Feature Request

    Is your feature request related to a problem? Please describe.

    Describe the solution you'd like

    Describe alternatives you've considered

    Are you willing to resolve this issue by submitting a Pull Request?

    • [ ] Yes, I have the time, and I know how to start.
    • [ ] Yes, I have the time, but I don't know how to start. I would need guidance.
    • [x] No, I don't have the time, although I believe I could do it if I had the time...
    • [ ] No, I don't have the time and I wouldn't even know how to start.
    opened by Rubilmax 0
  • Do not wrap query if there is only one query to do

    Do not wrap query if there is only one query to do

    Feature Request

    if I do await contract.function(), the data is encoded for multi-call, where I only want to do one query. It results in an overload for simple queries.

    Is your feature request related to a problem? Please describe.

    Describe the solution you'd like

    Describe alternatives you've considered

    Are you willing to resolve this issue by submitting a Pull Request?

    • [ ] Yes, I have the time, and I know how to start.
    • [ ] Yes, I have the time, but I don't know how to start. I would need guidance.
    • [x] No, I don't have the time, although I believe I could do it if I had the time...
    • [ ] No, I don't have the time and I wouldn't even know how to start.
    opened by julien-devatom 0
Releases(v3.0.1)
Owner
Morpho Labs
Morpho Labs
Patronum: Ethereum RPC proxy that verifies RPC responses against given trusted block hashes

Patronum Ethereum RPC proxy that verifies RPC responses against given trusted block hashes. Currently, most of the DAPPs and Wallets interact with Eth

null 14 Dec 7, 2022
an open-source package to make it easy and simple to work with RabbitMQ's RPC ( Remote Procedure Call )

RabbitMQ Easy RPC (Remote Procedure Call ) The Node.js's RabbitMQ Easy RPC Library rabbitmq-easy-RPC is an easy to use npm package for rabbitMQ's RPC

Ali Amjad 4 Sep 22, 2022
Cardinal generator encompasses serverless functions and smart contracts for rendering generative NFTs

Cardinal Generator An open protocol for generative NFTs. Background Cardinal generator encompasses serverless functions and smart contracts for render

Cardinal 31 Dec 6, 2022
100% type-safe query builder for node-postgres :: Generated types, call any function, tree-shakable, implicit type casts, and more

⚠️ This library is currently in alpha. Contributors wanted! tusken Postgres client from a galaxy far, far away. your database is the source-of-truth f

alloc 54 Dec 29, 2022
Minimal web3 implementation: call eth contracts directly from JS

micro-web3 Minimal web3 implementation: call eth contracts directly from JS Connect to any web3 server: host your own with execution layer client, or

Paul Miller 46 Dec 29, 2022
A simple query builder, it will helps to develop DSL query for Elasticsearch

Elasticsearch Dynamic Query Builder A simple query builder, it will helps to develop DSL query for elasticsearch Installation You can start it from np

Hashemi Rafsan 4 Nov 20, 2022
The invoker based on event model provides an elegant way to call your methods in another container via promisify functions

The invoker based on event model provides an elegant way to call your methods in another container via promisify functions. (like child-processes, iframe, web worker etc).

尹挚 7 Dec 29, 2022
fcall, fetch and call any remote hot functions, anywhere, anytime, without installations or configurations.

fcall, fetch and call any remote hot functions, anywhere, anytime, without installations or configurations.

η«‹ε…š Lidang 4 Sep 20, 2022
A collection of smart contracts for the Stackup platform πŸ€– πŸ“‘

Contracts A collection of smart contracts for the Stackup platform. Dev Blog Deployed Contracts See releases for deployed contracts of previous versio

Stackup 16 Nov 29, 2021
Ethereum Smart Contracts for locking your Ether and ERC20 tokens based on time and price conditions

SmartHold - a simple way to lock and hold your ETH or ERC20 in a smart contract This is a BETA software that has not been audited for security. USE AT

PaweΕ‚ Urbanek 22 May 5, 2022
♦ Crowd funding project using Smart Contracts on the Ethereum. Created with Next.js and Tailwind CSS.

Crowdcoin ♦ Crowd funding project using Smart Contracts on the Ethereum. Created with Next.js and Tailwind CSS. Project from "Ethereum and Solidity: T

Luiz Fernando VerΓ­ssimo 2 Dec 14, 2022
Cooperative databases using smart contracts.

Vitra β–ˆβ–ˆβ•— β–ˆβ–ˆβ•—β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ•β•β–ˆβ–ˆβ•”β•β•β•β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•— β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘ β•šβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•‘ β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆ

Paul Frazee 177 Dec 30, 2022
Run CosmWasm smart contracts in Node.js and web browsers

Run CosmWasm smart contracts in Node.js and web browsers

Terran One 31 Nov 25, 2022
A 'to do list' powered by Ethereum smart contracts

A 'to do list' powered by Ethereum smart contracts. built with JavaScript, Ganache, Truffle, Node.js, Metamask, jQuery, and Bootstrap

Christotle Agholor 3 Feb 17, 2022
Context-aware smart contracts for blockchain IoT systems

Context-aware smart contracts for blockchain IoT systems It contains 2 directories: contracts: contains the ContextAwareSmartContract.sol contract wit

ibelab 6 Jun 17, 2022
This is the main repository for NFT collection dao smart contracts.

Basic Sample Hardhat Project This project demonstrates a basic Hardhat use case. It comes with a sample contract, a test for that contract, a sample s

null 3 Apr 11, 2022
Yet another library for generating NFT artwork, uploading NFT assets and metadata to IPFS, deploying NFT smart contracts, and minting NFT collections

eznft Yet another library for generating NFT artwork, uploading NFT assets and metadata to IPFS, deploying NFT smart contracts, and minting NFT collec

null 3 Sep 21, 2022
a quick start boilerplate for developing web3 apps and deploying smart contracts.

create-web3 A boilerplate for starting a web3 project. This boilerplate quickly creates a mono repo with 2 environments, a Next JS environment for fro

Eric Roupe 83 Dec 16, 2022
πŸš€ NFTank (NFT tank for dummies) will allow developers to quickly request NFTs to personal wallets or smart contracts in just a few clicks.

??‍♂️ NFTank ?? NFTank (NFT tank for dummies) will allow developers to quickly request NFTs to personal wallets or smart contracts in just a few click

buidler's hub 8 Nov 8, 2022