-
Notifications
You must be signed in to change notification settings - Fork 1
/
Deployment.ts
41 lines (37 loc) · 1.48 KB
/
Deployment.ts
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
import { ethers } from "ethers";
import { Ballot__factory } from "../typechain-types";
import * as dotenv from 'dotenv';
dotenv.config()
const proposals = ["Proposal 1", "Proposal 2", "Proposal 3"];
function convertStringArrayToBytes32(array: string[]) {
const bytes32Array = [];
for (let index = 0; index < array.length; index++) {
bytes32Array.push(ethers.utils.formatBytes32String(array[index]));
}
return bytes32Array;
}
async function main() {
console.log("Deploying Ballot contract");
console.log("Proposals: ");
const proposals = process.argv.slice(2);
proposals.forEach((element, index) => {
console.log(`Proposal N. ${index + 1}: ${element}`);
});
const provider = ethers.getDefaultProvider("goerli", {alchemy: process.env.ALCHEMY_API_KEY});
const wallet = ethers.Wallet.fromMnemonic(process.env.MNEMONIC ?? "");
const signer = wallet.connect(provider);
console.log(`Connected to the wallet ${signer.address}`);
const balance = await signer.getBalance();
console.log(`This address has a balance of ${balance} wei`);
if (balance.eq(0)) throw new Error("Insufficient funds");
const ballotContractFactory = new Ballot__factory(signer);
const ballotContract = await ballotContractFactory.deploy(
convertStringArrayToBytes32(proposals)
);
await ballotContract.deployed();
console.log(`The ballot smart contract was deployed at ${ballotContract.address}`)
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});