Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pooltogether/etherplex
https://github.com/pooltogether/etherplex
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/pooltogether/etherplex
- Owner: pooltogether
- Created: 2020-05-01T21:55:16.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T11:13:15.000Z (almost 2 years ago)
- Last Synced: 2024-04-23T21:42:35.844Z (9 months ago)
- Language: TypeScript
- Size: 550 KB
- Stars: 65
- Watchers: 6
- Forks: 12
- Open Issues: 19
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Etherplex
[Ethers.js](https://github.com/ethers-io/ethers.js) + [Multicall](https://github.com/makerdao/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
```bash
$ yarn add @pooltogether/etherplex
```# Usage
1. First create a contract wrapper using the `contract` function
2. Chain calls on the contract and pass the results into the `batch` function```javascript
import { ethers } from 'ethers'
import { batch, contract } from '@pooltogether/etherplex'// Assuming ERC20Abi is an ABI
// Assume the DAI_ADDRESS and USDC_ADDRESS constants are Ethereum addresseslet 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],
}
}*/
```