10grans-ng/scripts/deploy-l2.ts

37 lines
1.1 KiB
TypeScript

import { ethers } from "hardhat";
import fs from "fs/promises";
import dotenv from "dotenv";
const env = process.env.NODE_ENV || "local";
dotenv.config({ path: `.env.${env}` });
async function main() {
if (!process.env.BRIDGE_ADDRESS) throw "Bridge address not defined";
if (!process.env.TOKEN_NAME) throw "Token name not defined";
if (!process.env.TOKEN_SYMBOL) throw "Token symbol not defined";
const L1TokenAddress = (await fs.readFile(`.l1-token-address.${env}`, "utf-8")).trim();
const L2Token = await ethers.deployContract(
"L2Token",
[
process.env.TOKEN_NAME,
process.env.TOKEN_SYMBOL,
process.env.BRIDGE_ADDRESS,
L1TokenAddress,
]
);
await L2Token.waitForDeployment();
const deployedAddress = await L2Token.getAddress();
console.log(`L2 token deployed to: ${deployedAddress}`);
await fs.writeFile(`.l2-token-address.${env}`, deployedAddress);
}
// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});