forked from Uniswap/web3-react
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathchains.ts
More file actions
167 lines (156 loc) · 4.88 KB
/
chains.ts
File metadata and controls
167 lines (156 loc) · 4.88 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import type { AddEthereumChainParameter } from '@web3-react/types'
const ETH: AddEthereumChainParameter['nativeCurrency'] = {
name: 'Ether',
symbol: 'ETH',
decimals: 18,
}
const MATIC: AddEthereumChainParameter['nativeCurrency'] = {
name: 'Matic',
symbol: 'MATIC',
decimals: 18,
}
const CELO: AddEthereumChainParameter['nativeCurrency'] = {
name: 'Celo',
symbol: 'CELO',
decimals: 18,
}
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}` : '',
process.env.alchemyKey ? `https://eth-mainnet.alchemyapi.io/v2/${process.env.alchemyKey}` : '',
'https://cloudflare-eth.com',
].filter((url) => url !== ''),
name: 'Mainnet',
},
3: {
urls: [process.env.infuraKey ? `https://ropsten.infura.io/v3/${process.env.infuraKey}` : ''].filter(
(url) => url !== ''
),
name: 'Ropsten',
},
4: {
urls: [process.env.infuraKey ? `https://rinkeby.infura.io/v3/${process.env.infuraKey}` : ''].filter(
(url) => url !== ''
),
name: 'Rinkeby',
},
5: {
urls: [process.env.infuraKey ? `https://goerli.infura.io/v3/${process.env.infuraKey}` : ''].filter(
(url) => url !== ''
),
name: 'Görli',
},
42: {
urls: [process.env.infuraKey ? `https://kovan.infura.io/v3/${process.env.infuraKey}` : ''].filter(
(url) => url !== ''
),
name: 'Kovan',
},
// Optimism
10: {
urls: [
process.env.infuraKey ? `https://optimism-mainnet.infura.io/v3/${process.env.infuraKey}` : '',
'https://mainnet.optimism.io',
].filter((url) => url !== ''),
name: 'Optimism',
nativeCurrency: ETH,
blockExplorerUrls: ['https://optimistic.etherscan.io'],
},
69: {
urls: [
process.env.infuraKey ? `https://optimism-kovan.infura.io/v3/${process.env.infuraKey}` : '',
'https://kovan.optimism.io',
].filter((url) => url !== ''),
name: 'Optimism Kovan',
nativeCurrency: ETH,
blockExplorerUrls: ['https://kovan-optimistic.etherscan.io'],
},
// Arbitrum
42161: {
urls: [
process.env.infuraKey ? `https://arbitrum-mainnet.infura.io/v3/${process.env.infuraKey}` : '',
'https://arb1.arbitrum.io/rpc',
].filter((url) => url !== ''),
name: 'Arbitrum One',
nativeCurrency: ETH,
blockExplorerUrls: ['https://arbiscan.io'],
},
421611: {
urls: [
process.env.infuraKey ? `https://arbitrum-rinkeby.infura.io/v3/${process.env.infuraKey}` : '',
'https://rinkeby.arbitrum.io/rpc',
].filter((url) => url !== ''),
name: 'Arbitrum Testnet',
nativeCurrency: ETH,
blockExplorerUrls: ['https://testnet.arbiscan.io'],
},
// Polygon
137: {
urls: [
process.env.infuraKey ? `https://polygon-mainnet.infura.io/v3/${process.env.infuraKey}` : '',
'https://polygon-rpc.com',
].filter((url) => url !== ''),
name: 'Polygon Mainnet',
nativeCurrency: MATIC,
blockExplorerUrls: ['https://polygonscan.com'],
},
80001: {
urls: [process.env.infuraKey ? `https://polygon-mumbai.infura.io/v3/${process.env.infuraKey}` : ''].filter(
(url) => url !== ''
),
name: 'Polygon Mumbai',
nativeCurrency: MATIC,
blockExplorerUrls: ['https://mumbai.polygonscan.com'],
},
// Celo
42220: {
urls: ['https://forno.celo.org'],
name: 'Celo',
nativeCurrency: CELO,
blockExplorerUrls: ['https://explorer.celo.org'],
},
44787: {
urls: ['https://alfajores-forno.celo-testnet.org'],
name: 'Celo Alfajores',
nativeCurrency: CELO,
blockExplorerUrls: ['https://alfajores-blockscout.celo-testnet.org'],
},
}
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
},
{}
)