Skip to content

Commit 64822c9

Browse files
committed
Create ESM and Commonjs flavor of config and env files
1 parent 64e5c1e commit 64822c9

File tree

4 files changed

+59
-42
lines changed

4 files changed

+59
-42
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Hardhat Ignition does not support ESM modules, so we use CommonJS syntax.
2+
// TODO refactor this to use ESM syntax when Hardhat Ignition supports it.
3+
4+
module.exports = {
5+
POCO_ADDRESS: '0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f',
6+
DATASET_REGISTRY_ADDRESS: '0x799DAa22654128d0C64d5b79eac9283008158730',
7+
APP_REGISTRY_ADDRESS: '0xB1C52075b276f87b1834919167312221d50c9D16',
8+
};
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
export const SMART_CONTRACT_ADDRESS_FILE = '.smart-contract-address';
2-
export const POCO_ADDRESS = '0x3eca1B216A7DF1C7689aEb259fFB83ADFB894E7f';
3-
export const DATASET_REGISTRY_ADDRESS = '0x799DAa22654128d0C64d5b79eac9283008158730';
4-
export const APP_REGISTRY_ADDRESS = '0xB1C52075b276f87b1834919167312221d50c9D16';
1+
import config from './config.cjs';
2+
3+
export const POCO_ADDRESS = config.POCO_ADDRESS;
4+
export const DATASET_REGISTRY_ADDRESS = config.DATASET_REGISTRY_ADDRESS;
5+
export const APP_REGISTRY_ADDRESS = config.APP_REGISTRY_ADDRESS;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Hardhat Ignition does not support ESM modules, so we use CommonJS syntax.
2+
// TODO refactor this to use ESM syntax when Hardhat Ignition supports it.
3+
4+
require('dotenv/config.js');
5+
const { z } = require('zod');
6+
7+
const addressRegex = /(^|\b)(0x)?[0-9a-fA-F]{64}(\b|$)/;
8+
const privateKeyRegex = /(^|\b)(0x)?[0-9a-fA-F]{64}(\b|$)/;
9+
10+
const envSchema = z.object({
11+
// Private key of the wallet used for transactions
12+
WALLET_PRIVATE_KEY: z
13+
.string()
14+
.regex(privateKeyRegex, 'Invalid private key format')
15+
.optional()
16+
.or(z.literal('')),
17+
18+
// environment to use for configuration (prod/staging)
19+
ENV: z.enum(['prod', 'staging'], 'ENV must be either "prod" or "staging"').default('prod'),
20+
21+
// Address of the PoCo contract
22+
POCO_ADDRESS: z
23+
.string()
24+
.regex(addressRegex, 'Invalid Ethereum address format')
25+
.optional()
26+
.or(z.literal('')),
27+
28+
// Address of the DatasetRegistry
29+
DATASET_REGISTRY_ADDRESS: z
30+
.string()
31+
.regex(addressRegex, 'Invalid Ethereum address format')
32+
.optional()
33+
.or(z.literal('')),
34+
35+
// URL of the RPC used for network connection
36+
RPC_URL: z.string().url('RPC_URL must be a valid URL').optional().or(z.literal('')),
37+
38+
// Mnemonic for deployment or network interaction
39+
MNEMONIC: z.string().min(1, 'MNEMONIC cannot be empty').optional().or(z.literal('')),
40+
});
41+
42+
module.exports = {
43+
env: envSchema.parse(process.env),
44+
};
Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,3 @@
1-
import 'dotenv/config.js';
2-
import { z } from 'zod';
1+
import env from './env.cjs';
32

4-
const addressRegex = /(^|\b)(0x)?[0-9a-fA-F]{64}(\b|$)/;
5-
const privateKeyRegex = /(^|\b)(0x)?[0-9a-fA-F]{64}(\b|$)/;
6-
7-
const envSchema = z.object({
8-
// Private key of the wallet used for transactions
9-
WALLET_PRIVATE_KEY: z
10-
.string()
11-
.regex(privateKeyRegex, 'Invalid private key format')
12-
.optional()
13-
.or(z.literal('')),
14-
15-
// environment to use for configuration (prod/staging)
16-
ENV: z.enum(['prod', 'staging'], 'ENV must be either "prod" or "staging"').default('prod'),
17-
18-
// Address of the PoCo contract
19-
POCO_ADDRESS: z
20-
.string()
21-
.regex(addressRegex, 'Invalid Ethereum address format')
22-
.optional()
23-
.or(z.literal('')),
24-
25-
// Address of the DatasetRegistry
26-
DATASET_REGISTRY_ADDRESS: z
27-
.string()
28-
.regex(addressRegex, 'Invalid Ethereum address format')
29-
.optional()
30-
.or(z.literal('')),
31-
32-
// URL of the RPC used for network connection
33-
RPC_URL: z.string().url('RPC_URL must be a valid URL').optional().or(z.literal('')),
34-
35-
// Mnemonic for deployment or network interaction
36-
MNEMONIC: z.string().min(1, 'MNEMONIC cannot be empty').optional().or(z.literal('')),
37-
});
38-
39-
export const env = envSchema.parse(process.env);
3+
export const env = env.env;

0 commit comments

Comments
 (0)