-
Notifications
You must be signed in to change notification settings - Fork 1
/
usdc-plugin.example.ts
55 lines (51 loc) · 1.18 KB
/
usdc-plugin.example.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
yarn add web3
yarn add web3-multicall3
*/
import Web3 from 'web3';
import { createContractCall } from 'web3-multicall3';
import { Web3Multicall3Plugin } from 'web3-multicall3/plugin';
export const UsdcAbi = [
{
"inputs": [
{
"internalType": "address",
"name": "account",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "owner",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
] as const;
const web3 = new Web3('https://1rpc.io/eth');
web3.registerPlugin(new Web3Multicall3Plugin());
async function main() {
const usdc = new web3.eth.Contract(UsdcAbi, '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48');
const [owner, balance] = await web3.multicall3.aggregate3([
createContractCall(usdc, 'owner', []),
createContractCall(usdc, 'balanceOf', ['0x0000000000000000000000000000000000000000']),
]);
}
main()