-
Notifications
You must be signed in to change notification settings - Fork 20
/
getContractData.ts
38 lines (33 loc) · 913 Bytes
/
getContractData.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
import {ethers} from 'ethers';
import {checksum, getRandomInt, _log} from '../configs/utils';
import {erc20abi} from './abis-interfaces';
import {MAINNET} from './utils';
const getContractData = async (
contractAddress: string,
providers: Array<any>
): Promise<any> => {
try {
const address = checksum(contractAddress);
const contract = new ethers.Contract(
address,
erc20abi,
providers[getRandomInt(1, providers.length - 1)]
);
const [decimals, name, symbol] = await Promise.all([
contract.functions.decimals(),
contract.functions.name(),
contract.functions.symbol(),
]);
return {
chainId: MAINNET,
address,
decimals: decimals[0],
name: name[0],
symbol: symbol[0],
};
} catch (e: any) {
_log.error('GetContractData catch', contractAddress, e);
}
return null;
};
export {getContractData, MAINNET};