Skip to content

Commit ecca9cb

Browse files
committed
Share constants for filenames in contract deploy and faucet scripts
1 parent 13bd712 commit ecca9cb

File tree

4 files changed

+38
-15
lines changed

4 files changed

+38
-15
lines changed

constants.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// const FRONTEND_SRC_PATH = "frontend";
2+
const path = require("path");
3+
4+
const FRONTEND_SRC_PATH = "frontend";
5+
6+
export const TOKEN_JSON_FILE = "Token.json";
7+
export const CONTRACT_OUTPUT_FILENAME = "contract-address.json";
8+
export const CONTRACTS_DIRECTORY = path.join(
9+
__dirname,
10+
".",
11+
FRONTEND_SRC_PATH,
12+
"src",
13+
"contracts"
14+
);
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = {
1010
solidity: "0.8.9",
1111
networks: {
1212
hardhat: {
13-
chainId: 1337 // We set 1337 to make interacting with MetaMask simpler
14-
}
15-
}
13+
chainId: 31337, // We set 1337 to make interacting with MetaMask simpler
14+
},
15+
},
1616
};
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
// This is a script for deploying your contracts. You can adapt it to deploy
22
// yours, or create new ones.
33

4-
const path = require("path");
4+
import fs from "fs";
5+
import path from "path";
6+
7+
const {
8+
CONTRACTS_DIRECTORY,
9+
CONTRACT_OUTPUT_FILENAME,
10+
TOKEN_JSON_FILE,
11+
} = require("../constants");
512

613
async function main() {
714
// This is just a convenience check
@@ -33,22 +40,19 @@ async function main() {
3340
}
3441

3542
function saveFrontendFiles(token) {
36-
const fs = require("fs");
37-
const contractsDir = path.join(__dirname, "..", "frontend", "src", "contracts");
38-
39-
if (!fs.existsSync(contractsDir)) {
40-
fs.mkdirSync(contractsDir);
43+
if (!fs.existsSync(CONTRACTS_DIRECTORY)) {
44+
fs.mkdirSync(CONTRACTS_DIRECTORY);
4145
}
4246

4347
fs.writeFileSync(
44-
path.join(contractsDir, "contract-address.json"),
48+
path.join(CONTRACTS_DIRECTORY, CONTRACT_OUTPUT_FILENAME),
4549
JSON.stringify({ Token: token.address }, undefined, 2)
4650
);
4751

4852
const TokenArtifact = artifacts.readArtifactSync("Token");
4953

5054
fs.writeFileSync(
51-
path.join(contractsDir, "Token.json"),
55+
path.join(CONTRACTS_DIRECTORY, TOKEN_JSON_FILE),
5256
JSON.stringify(TokenArtifact, null, 2)
5357
);
5458
}

tasks/faucet.js renamed to tasks/faucet.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
const fs = require("fs");
1+
import fs from "fs";
2+
import path from "path";
3+
4+
const {
5+
CONTRACTS_DIRECTORY,
6+
CONTRACT_OUTPUT_FILENAME,
7+
} = require("../constants");
8+
9+
const addressesFile = path.join(CONTRACTS_DIRECTORY, CONTRACT_OUTPUT_FILENAME);
210

311
// This file is only here to make interacting with the Dapp easier,
412
// feel free to ignore it if you don't need it.
@@ -14,9 +22,6 @@ task("faucet", "Sends ETH and tokens to an address")
1422
);
1523
}
1624

17-
const addressesFile =
18-
__dirname + "/../frontend/src/contracts/contract-address.json";
19-
2025
if (!fs.existsSync(addressesFile)) {
2126
console.error("You need to deploy your contract first");
2227
return;

0 commit comments

Comments
 (0)