-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhardhat.config.js
More file actions
100 lines (93 loc) · 2.64 KB
/
Copy pathhardhat.config.js
File metadata and controls
100 lines (93 loc) · 2.64 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
require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();
const fs = require("fs");
const path = require("path");
// Define a new Hardhat task to set the sale state.
// This is the idiomatic way to handle command-line arguments in Hardhat.
task("set-sale-state", "Sets the sale state of the NFT contract")
.addPositionalParam(
"state",
"The desired sale state (closed, presale, public)"
)
.setAction(async (taskArgs, hre) => {
const stateArg = taskArgs.state.toLowerCase();
const stateMap = {
closed: 0,
presale: 1,
airdrop: 1,
public: 2,
publicsale: 2,
};
const newState = stateMap[stateArg];
if (newState === undefined) {
console.error(
`❌ Error: Invalid state argument '${stateArg}'. Please use 'closed', 'presale', or 'public'.`
);
process.exit(1);
}
const stateName = Object.keys(stateMap).find(
(key) => stateMap[key] === newState
);
const { nft: nftAddress } = JSON.parse(
fs.readFileSync(path.join(__dirname, "deployed-addresses.json"))
);
if (!nftAddress) {
throw new Error(
"Could not find deployed NFT contract address in deployed-addresses.json"
);
}
const [owner] = await hre.ethers.getSigners();
const nft = await hre.ethers.getContractAt(
"AdvancedNFT",
nftAddress,
owner
);
console.log(`\nSetting sale state on contract ${nftAddress}...`);
console.log(` - Network: ${hre.network.name}`);
console.log(` - Signer: ${owner.address}`);
console.log(` - New State: ${stateName.toUpperCase()} (${newState})`);
try {
const tx = await nft.setSaleState(newState);
console.log(` - Transaction sent: ${tx.hash}`);
await tx.wait();
console.log("\n✅ Sale state successfully updated!");
} catch (e) {
console.error("\n❌ Error during transaction:", e.message);
process.exit(1);
}
});
/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: {
version: "0.8.24",
settings: {
optimizer: {
enabled: true,
runs: 200,
},
},
},
paths: {
sources: "./contracts",
tests: "./test",
cache: "./cache",
artifacts: "./artifacts",
},
networks: {
hardhat: {
chainId: 1337, // Standard for local development
},
localhost: {
chainId: 1337,
url: "http://127.0.0.1:8545",
},
sepolia: {
url: process.env.SEPOLIA_RPC_URL || "",
accounts:
process.env.PRIVATE_KEY !== undefined ? [process.env.PRIVATE_KEY] : [],
},
},
etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY,
},
};