-
Notifications
You must be signed in to change notification settings - Fork 571
Expand file tree
/
Copy pathdeploy.ts
More file actions
65 lines (52 loc) · 1.68 KB
/
deploy.ts
File metadata and controls
65 lines (52 loc) · 1.68 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
// This is a script for deploying your contracts. You can adapt it to deploy
// yours, or create new ones.
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
if (network.name === "hardhat") {
console.warn(
"You are trying to deploy a contract to the Hardhat Network, which" +
"gets automatically created and destroyed every time. Use the Hardhat" +
" option '--network localhost'"
);
}
// ethers is available in the global scope
const [deployer] = await ethers.getSigners();
console.log(
"Deploying the contracts with the account:",
await deployer.getAddress()
);
console.log("Account balance:", (await deployer.getBalance()).toString());
const Token = await ethers.getContractFactory("Token");
const token = await Token.deploy();
await token.deployed();
console.log("Token address:", token.address);
// We also save the contract's artifacts and address in the frontend directory
saveFrontendFiles(token);
}
function saveFrontendFiles(token) {
if (!fs.existsSync(CONTRACTS_DIRECTORY)) {
fs.mkdirSync(CONTRACTS_DIRECTORY);
}
fs.writeFileSync(
path.join(CONTRACTS_DIRECTORY, CONTRACT_OUTPUT_FILENAME),
JSON.stringify({ Token: token.address }, undefined, 2)
);
const TokenArtifact = artifacts.readArtifactSync("Token");
fs.writeFileSync(
path.join(CONTRACTS_DIRECTORY, TOKEN_JSON_FILE),
JSON.stringify(TokenArtifact, null, 2)
);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});