-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathprovidersUrls.ts
65 lines (57 loc) · 2.05 KB
/
providersUrls.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
import { CHAINS } from '@lido-sdk/constants';
import invariant from 'tiny-invariant';
export const getInfuraRPCUrl = (chainId: CHAINS, apiKey: string): string => {
invariant(apiKey && typeof apiKey === 'string', 'API key should be a string');
switch (chainId) {
case CHAINS.Mainnet:
return `https://mainnet.infura.io/v3/${apiKey}`;
case CHAINS.Ropsten:
return `https://ropsten.infura.io/v3/${apiKey}`;
case CHAINS.Rinkeby:
return `https://rinkeby.infura.io/v3/${apiKey}`;
case CHAINS.Goerli:
return `https://goerli.infura.io/v3/${apiKey}`;
case CHAINS.Kovan:
return `https://kovan.infura.io/v3/${apiKey}`;
case CHAINS.Holesky:
return `https://holesky.infura.io/v3/${apiKey}`;
case CHAINS.Sepolia:
return `https://sepolia.infura.io/v3/${apiKey}`;
default:
invariant(false, 'Chain is not supported');
}
};
export const getAlchemyRPCUrl = (chainId: CHAINS, apiKey: string): string => {
invariant(apiKey && typeof apiKey === 'string', 'API key should be a string');
switch (chainId) {
case CHAINS.Mainnet:
return `https://eth-mainnet.alchemyapi.io/v2/${apiKey}`;
case CHAINS.Ropsten:
return `https://eth-ropsten.alchemyapi.io/v2/${apiKey}`;
case CHAINS.Rinkeby:
return `https://eth-rinkeby.alchemyapi.io/v2/${apiKey}`;
case CHAINS.Goerli:
return `https://eth-goerli.alchemyapi.io/v2/${apiKey}`;
case CHAINS.Kovan:
return `https://eth-kovan.alchemyapi.io/v2/${apiKey}`;
case CHAINS.Holesky:
return `https://eth-holesky.alchemyapi.io/v2/${apiKey}`;
case CHAINS.Sepolia:
return `https://eth-sepolia.g.alchemy.com/v2/${apiKey}`;
default:
invariant(false, 'Chain is not supported');
}
};
export interface RPCProvidersKeys {
infura?: string;
alchemy?: string;
}
export const getRPCUrls = (
chainId: CHAINS,
keys: RPCProvidersKeys,
): string[] => {
const urls = [];
if (keys.alchemy) urls.push(getAlchemyRPCUrl(chainId, keys.alchemy));
if (keys.infura) urls.push(getInfuraRPCUrl(chainId, keys.infura));
return urls;
};