-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.ts
51 lines (41 loc) · 1.72 KB
/
config.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
const LOCAL = process.env.NEXT_PUBLIC_LOCAL === "true";
const IS_BROWSER = (typeof window === 'undefined') ? false : true;
/**
* This function lets us validate that the env variables we need are defined
* and so we can fail early and let the developer fix their environment at
* startup time.
*/
function checkStr(str: string | undefined, varName: string): string {
if (!str) {
if (IS_BROWSER && !varName.startsWith('NEXT_PUBLIC_')) {
// These variables are never available in the browser, so we can't
// check them.
return str as string;
}
throw new Error(`Env variable "${varName}" not defined or empty`);
}
return str;
}
const RPC_URL = LOCAL
? "http://localhost:8545"
: `https://eth-sepolia.g.alchemy.com/v2/${checkStr(process.env.NEXT_PUBLIC_ALCHEMY_API_KEY, 'NEXT_PUBLIC_ALCHEMY_API_KEY')}`;
console.log("RPC= ", RPC_URL)
const CHAIN_ID = LOCAL
? parseInt(checkStr(process.env.NEXT_PUBLIC_LOCAL_CHAIN_ID, 'NEXT_PUBLIC_LOCAL_CHAIN_ID'))
: parseInt(checkStr(process.env.NEXT_PUBLIC_SEPOLIA_CHAIN_ID, 'NEXT_PUBLIC_SEPOLIA_CHAIN_ID'));
const DSV_CONTRACT = LOCAL
? checkStr(process.env.NEXT_PUBLIC_LOCAL_CONTRACT_ADDRESS, 'NEXT_PUBLIC_LOCAL_CONTRACT_ADDRESS')
: checkStr(process.env.NEXT_PUBLIC_SEPOLIA_CONTRACT_ADDRESS, 'NEXT_PUBLIC_SEPOLIA_CONTRACT_ADDRESS');
const ADMIN_ADDRESS = LOCAL
? checkStr(process.env.LOCAL_ADMIN_ADDRESS, 'LOCAL_ADMIN_ADDRESS')
: checkStr(process.env.SEPOLIA_ADMIN_ADDRESS, 'SEPOLIA_ADMIN_ADDRESS');
export const CONFIG_SERVER = {
RPC_URL,
ADMIN_ADDRESS,
};
export const CONFIG_FRONT = {
CHAIN_ID,
DSV_CONTRACT,
};
console.log(`CONFIG_SERVER: ${JSON.stringify(CONFIG_SERVER, null, 2)}`);
console.log(`CONFIG_FRONT: ${JSON.stringify(CONFIG_FRONT, null, 2)}`);