-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhardhat.config.ts
More file actions
130 lines (121 loc) · 4.31 KB
/
hardhat.config.ts
File metadata and controls
130 lines (121 loc) · 4.31 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
import { HardhatUserConfig, task } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import "@nomicfoundation/hardhat-verify/etherscan"; // Import the verify plugin
import "@openzeppelin/hardhat-upgrades";
import "@typechain/hardhat";
import * as dotenv from "dotenv";
dotenv.config();
// Validate essential environment variables for Celo mainnet
const mainnetCeloRpcUrl = process.env.MAINNET_CELO_RPC_URL;
const arbitratorPrivateKey = process.env.ARBITRATOR_PRIVATE_KEY;
const mainnetCeloChainIdString = process.env.MAINNET_CELO_CHAIN_ID;
// Use the user-specified environment variable for the general CeloScan API key
const envCeloscanApiKey = process.env.CELOSCAN_API_KEY; // This can be undefined
if (!mainnetCeloRpcUrl) {
console.warn("MAINNET_CELO_RPC_URL not found in .env. Celo mainnet operations might fail.");
}
if (!arbitratorPrivateKey) {
console.warn("ARBITRATOR_PRIVATE_KEY not found in .env. Celo mainnet operations might fail.");
}
if (!mainnetCeloChainIdString) {
console.warn("MAINNET_CELO_CHAIN_ID not found in .env. Celo mainnet operations might fail.");
}
const mainnetCeloChainId = mainnetCeloChainIdString ? parseInt(mainnetCeloChainIdString) : 42220; // Default to Celo mainnet Chain ID
// Define a task to check balance
task("check-balance", "Prints the balance of the deployer account on the specified network")
.addOptionalParam("account", "The account's address (optional, defaults to the first signer)")
.setAction(async (taskArgs, hre) => {
const { ethers } = hre;
let addressToCheck;
if (taskArgs.account) {
addressToCheck = taskArgs.account;
console.log(`Checking balance for specified account: ${addressToCheck} on network ${hre.network.name}`);
} else {
const signers = await ethers.getSigners();
if (!signers || signers.length === 0) {
console.error("No signers configured for this network. Ensure your Hardhat network configuration has accounts set up.");
return;
}
const deployer = signers[0];
addressToCheck = await deployer.getAddress();
console.log(`Checking balance for default deployer account: ${addressToCheck} on network ${hre.network.name}`);
}
if (!addressToCheck) {
console.error("Could not determine address to check.");
return;
}
try {
const balance = await ethers.provider.getBalance(addressToCheck);
console.log(`Balance: ${ethers.formatEther(balance)} CELO`);
} catch (e: any) {
console.error(`Failed to fetch balance for ${addressToCheck} on network ${hre.network.name}.`);
if (e instanceof Error) {
console.error("Error details:", e.message);
} else {
console.error("An unexpected error occurred:", e);
}
console.error("Ensure your RPC URL is correct and the network is reachable.");
}
});
const config: HardhatUserConfig = {
solidity: {
version: "0.8.17",
settings: {
optimizer: {
enabled: true,
runs: 200
},
viaIR: true
}
},
networks: {
hardhat: {
chainId: 31337,
},
localhost: {
chainId: 31337,
},
alfajores: {
url: process.env.ALFAJORES_RPC_URL || "https://alfajores-forno.celo-testnet.org",
accounts: process.env.ARBITRATOR_PRIVATE_KEY ? [process.env.ARBITRATOR_PRIVATE_KEY] : [],
chainId: 44787
},
celo: {
url: mainnetCeloRpcUrl || "",
accounts: arbitratorPrivateKey ? [arbitratorPrivateKey] : [],
chainId: mainnetCeloChainId,
}
},
typechain: {
outDir: "typechain",
target: "ethers-v6",
},
etherscan: {
apiKey: {
alfajores: process.env.CELOSCAN_API_KEY || envCeloscanApiKey || "", // Use specific, then general, then empty string
celo: process.env.CELOSCAN_API_KEY || envCeloscanApiKey || "" // Use specific, then general, then empty string
},
customChains: [
{
network: "alfajores",
chainId: 44787,
urls: {
apiURL: "https://api-alfajores.celoscan.io/api",
browserURL: "https://alfajores.celoscan.io"
}
},
{
network: "celo",
chainId: mainnetCeloChainId,
urls: {
apiURL: "https://api.celoscan.io/api",
browserURL: "https://celoscan.io",
},
},
]
},
sourcify: {
enabled: true
},
};
export default config;