-
Notifications
You must be signed in to change notification settings - Fork 1k
/
deploy-erc20.ts
53 lines (41 loc) · 1.89 KB
/
deploy-erc20.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
42
43
44
45
46
47
48
49
50
51
52
53
import { Wallet } from "zksync-web3";
import * as ethers from "ethers";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
// load env file
import dotenv from "dotenv";
dotenv.config();
// load wallet private key from env file
const PRIVATE_KEY = process.env.WALLET_PRIVATE_KEY || "";
if (!PRIVATE_KEY)
throw "⛔️ Private key not detected! Add it to the .env file!";
// An example of a deploy script that will deploy and call a simple contract.
export default async function (hre: HardhatRuntimeEnvironment) {
// Initialize the wallet.
const wallet = new Wallet(PRIVATE_KEY);
// Create deployer object and load the artifact of the contract you want to deploy.
const deployer = new Deployer(hre, wallet);
const artifact = await deployer.loadArtifact("zkToken");
console.log(
`Running deploy script for the ${artifact.contractName} contract`
);
// Estimate contract deployment fee
const deploymentFee = await deployer.estimateDeployFee(artifact, []);
const parsedFee = ethers.utils.formatEther(deploymentFee.toString());
console.log(`The deployment is estimated to cost ${parsedFee} ETH`);
// ⚠️ OPTIONAL: Deposit funds to L2
// const depositHandle = await deployer.zkWallet.deposit({
// to: deployer.zkWallet.address,
// token: utils.ETH_ADDRESS,
// amount: deploymentFee.mul(2),
// });
// // Wait until the deposit is processed on zkSync
// await depositHandle.wait();
// Deploy this contract. The returned object will be of a `Contract` type, similarly to ones in `ethers`.
const contract = await deployer.deploy(artifact);
//obtain the Constructor Arguments
console.log("constructor args:" + contract.interface.encodeDeploy([]));
// Show the contract info.
const contractAddress = contract.address;
console.log(`${artifact.contractName} was deployed to ${contractAddress}`);
}