-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathchains.ts
82 lines (73 loc) · 2.47 KB
/
chains.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// @ts-nocheck
import type { AddEthereumChainParameter } from '@web3-react/types'
interface BasicChainInformation {
urls: string[]
name: string
}
interface ExtendedChainInformation extends BasicChainInformation {
nativeCurrency: AddEthereumChainParameter['nativeCurrency']
blockExplorerUrls: AddEthereumChainParameter['blockExplorerUrls']
}
function isExtendedChainInformation(
chainInformation: BasicChainInformation | ExtendedChainInformation
): chainInformation is ExtendedChainInformation {
return !!(chainInformation as ExtendedChainInformation).nativeCurrency
}
export function getAddChainParameters(chainId: number): AddEthereumChainParameter | number {
const chainInformation = CHAINS[chainId]
if (isExtendedChainInformation(chainInformation)) {
return {
chainId,
chainName: chainInformation.name,
nativeCurrency: chainInformation.nativeCurrency,
rpcUrls: chainInformation.urls,
blockExplorerUrls: chainInformation.blockExplorerUrls,
}
} else {
return chainId
}
}
export const CHAINS: { [chainId: number]: BasicChainInformation | ExtendedChainInformation } = {
1: {
urls: [
process.env.infuraKey ? `https://mainnet.infura.io/v3/${process.env.infuraKey}` : undefined,
process.env.alchemyKey ? `https://eth-mainnet.alchemyapi.io/v2/${process.env.alchemyKey}` : undefined,
'https://cloudflare-eth.com',
].filter((url) => url !== undefined),
name: 'Mainnet',
},
3: {
urls: [process.env.infuraKey ? `https://ropsten.infura.io/v3/${process.env.infuraKey}` : undefined].filter(
(url) => url !== undefined
),
name: 'Ropsten',
},
4: {
urls: [process.env.infuraKey ? `https://rinkeby.infura.io/v3/${process.env.infuraKey}` : undefined].filter(
(url) => url !== undefined
),
name: 'Rinkeby',
},
5: {
urls: [process.env.infuraKey ? `https://goerli.infura.io/v3/${process.env.infuraKey}` : undefined].filter(
(url) => url !== undefined
),
name: 'Görli',
},
42: {
urls: [process.env.infuraKey ? `https://kovan.infura.io/v3/${process.env.infuraKey}` : undefined].filter(
(url) => url !== undefined
),
name: 'Kovan',
},
}
export const URLS: { [chainId: number]: string[] } = Object.keys(CHAINS).reduce<{ [chainId: number]: string[] }>(
(accumulator, chainId) => {
const validURLs: string[] = CHAINS[Number(chainId)].urls
if (validURLs.length) {
accumulator[Number(chainId)] = validURLs
}
return accumulator
},
{}
)