diff --git a/scripts/deploy.js b/scripts/deploy.ts similarity index 75% rename from scripts/deploy.js rename to scripts/deploy.ts index 228e26d..6853712 100644 --- a/scripts/deploy.js +++ b/scripts/deploy.ts @@ -1,6 +1,12 @@ +import { ContractFactory } from "ethers"; +import { run, ethers, network, artifacts } from "hardhat"; +import { Artifact } from "hardhat/types"; +import { Lottery } from "../typechain-types"; + // This is a script for deploying your contracts. You can adapt it to deploy // yours, or create new ones. async function main() { + await run("compile"); // This is just a convenience check if (network.name === "hardhat") { console.warn( @@ -19,8 +25,8 @@ async function main() { console.log("Account balance:", (await deployer.getBalance()).toString()); - const Lottery = await ethers.getContractFactory("Lottery"); - const lottery = await Lottery.deploy(); + const Lottery: ContractFactory = await ethers.getContractFactory("Lottery"); + const lottery: Lottery = (await Lottery.deploy()) as Lottery; await lottery.deployed(); console.log("Lottery contract address:", lottery.address); @@ -29,7 +35,7 @@ async function main() { saveFrontendFiles(lottery); } -function saveFrontendFiles(lottery) { +function saveFrontendFiles(lottery: Lottery) { const fs = require("fs"); const contractsDir = __dirname + "/../frontend/src/contracts"; @@ -42,7 +48,7 @@ function saveFrontendFiles(lottery) { JSON.stringify({ Lottery: lottery.address }, undefined, 2) ); - const LotteryArtifact = artifacts.readArtifactSync("Lottery"); + const LotteryArtifact: Artifact = artifacts.readArtifactSync("Lottery"); fs.writeFileSync( contractsDir + "/Lottery.json",