🚀. Socket Launch Week Day 3:Socket Firewall Now Blocks Malicious VS Code and Open VSX Extensions.Learn more
Sign In

@leap-network/etherplex

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@leap-network/etherplex

Multicall with Ethers.js

latest
Source
npmnpm
Version
1.1.8
Version published
Weekly downloads
2
-85.71%
Maintainers
1
Weekly downloads
 
Created
Source

Etherplex

Ethers.js + Multicall

Batch multiple Ethereum JSON RPC calls into a single RPC call.

Features:

  • Uses the Multicall contract when available
  • Falls back to individual RPC requests when not available

Setup

yarn add @leap-network/etherplex

Usage

  • First create a contract wrapper using the contract function
  • Chain calls on the contract and pass the results into the batch function
import { ethers } from 'ethers'
import { batch, contract } from '@leap-network/etherplex'

// Assuming ERC20Abi is an ABI
// Assume the DAI_ADDRESS and USDC_ADDRESS constants are Ethereum addresses

let daiContract = contract('Dai', ERC20Abi, DAI_ADDRESS)

// Alternatively, you can just pass in an ethers.Contract instance
let ethersContract = new ethers.Contract(USDC_ADDRESS, ERC20Abi, provider)
let usdcContract = contract('Usdc', ethersContract)

let results = await batch(
  ethers.getDefaultProvider(),
  daiContract
    .balanceOf(address)
    .totalSupply(),
  usdcContract
    .balanceOf(address)
    .totalSupply()
)
/*
Will yield:

{
  Dai: {
    'balanceOf(address)': [BigNumber],
    balanceOf: [BigNumber],
  },
  Usdc: {
    'balanceOf(address)': [BigNumber],
    balanceOf: [BigNumber],
  }
}

*/

FAQs

Package last updated on 12 Aug 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