Skip to content

Commit 897cfc1

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

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Then, on a new terminal, go to the repository's root folder and run this to
3030
deploy your contract:
3131

3232
```sh
33-
npx hardhat run scripts/deploy.js --network localhost
33+
npx hardhat run scripts/deploy.ts --network localhost
3434
```
3535

3636
Finally, we can run the frontend with:
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)