diff --git a/README.md b/README.md index d54b1236..28d4b4a7 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Then, on a new terminal, go to the repository's root folder and run this to deploy your contract: ```sh -npx hardhat run scripts/deploy.js --network localhost +npx hardhat run scripts/deploy.ts --network localhost ``` Finally, we can run the frontend with: diff --git a/scripts/deploy.js b/scripts/deploy.ts similarity index 79% rename from scripts/deploy.js rename to scripts/deploy.ts index 4e59c61d..b1b650b1 100644 --- a/scripts/deploy.js +++ b/scripts/deploy.ts @@ -1,7 +1,14 @@ // This is a script for deploying your contracts. You can adapt it to deploy // yours, or create new ones. -const path = require("path"); +import fs from "fs"; +import path from "path"; + +const { + CONTRACTS_DIRECTORY, + CONTRACT_OUTPUT_FILENAME, + TOKEN_JSON_FILE, +} = require("../constants"); async function main() { // This is just a convenience check @@ -33,22 +40,19 @@ async function main() { } function saveFrontendFiles(token) { - const fs = require("fs"); - const contractsDir = path.join(__dirname, "..", "frontend", "src", "contracts"); - - if (!fs.existsSync(contractsDir)) { - fs.mkdirSync(contractsDir); + if (!fs.existsSync(CONTRACTS_DIRECTORY)) { + fs.mkdirSync(CONTRACTS_DIRECTORY); } fs.writeFileSync( - path.join(contractsDir, "contract-address.json"), + path.join(CONTRACTS_DIRECTORY, CONTRACT_OUTPUT_FILENAME), JSON.stringify({ Token: token.address }, undefined, 2) ); const TokenArtifact = artifacts.readArtifactSync("Token"); fs.writeFileSync( - path.join(contractsDir, "Token.json"), + path.join(CONTRACTS_DIRECTORY, TOKEN_JSON_FILE), JSON.stringify(TokenArtifact, null, 2) ); } diff --git a/tasks/faucet.js b/tasks/faucet.ts similarity index 86% rename from tasks/faucet.js rename to tasks/faucet.ts index 6baa42ec..85239c71 100644 --- a/tasks/faucet.js +++ b/tasks/faucet.ts @@ -1,4 +1,12 @@ -const fs = require("fs"); +import fs from "fs"; +import path from "path"; + +const { + CONTRACTS_DIRECTORY, + CONTRACT_OUTPUT_FILENAME, +} = require("../constants"); + +const addressesFile = path.join(CONTRACTS_DIRECTORY, CONTRACT_OUTPUT_FILENAME); // This file is only here to make interacting with the Dapp easier, // feel free to ignore it if you don't need it. @@ -14,9 +22,6 @@ task("faucet", "Sends ETH and tokens to an address") ); } - const addressesFile = - __dirname + "/../frontend/src/contracts/contract-address.json"; - if (!fs.existsSync(addressesFile)) { console.error("You need to deploy your contract first"); return;