-
Notifications
You must be signed in to change notification settings - Fork 93
/
TxHistoryProvider.ts
52 lines (45 loc) · 1.51 KB
/
TxHistoryProvider.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
import { BigNumber, BigNumberish, EtherscanProvider } from '../ethers';
let _isCommunityResource = false;
export class TxHistoryProvider extends EtherscanProvider {
constructor(chainId: BigNumberish, apiKey?: string) {
const _chainId = BigNumber.from(chainId).toNumber();
if (!apiKey) _isCommunityResource = true;
let defaultApiKey: string;
switch (_chainId) {
case 1: // mainnet
case 5: // goerli
defaultApiKey = <string>process.env.ETHERSCAN_API_KEY;
break;
case 10: // optimism
defaultApiKey = <string>process.env.OPTIMISTIC_ETHERSCAN_API_KEY;
break;
case 137: // polygon
defaultApiKey = <string>process.env.POLYGONSCAN_API_KEY;
break;
case 42161: // arbitrum
defaultApiKey = <string>process.env.ARBISCAN_API_KEY;
break;
default:
throw new Error(`Unsupported chain ID ${_chainId}`);
}
super(_chainId, apiKey || defaultApiKey);
}
getBaseUrl(): string {
switch (BigNumber.from(this.network.chainId).toNumber()) {
case 1:
return 'https://api.etherscan.io';
case 5:
return 'https://api-goerli.etherscan.io';
case 10:
return 'https://api-optimistic.etherscan.io';
case 137:
return 'https://api.polygonscan.com';
case 42161:
return 'https://api.arbiscan.io';
}
throw new Error(`Unsupported network ${JSON.stringify(this.network.chainId)}`);
}
isCommunityResource(): boolean {
return _isCommunityResource;
}
}