async function main() {
const [deployer] = await ethers.getSigners();
console.log("Deploying contracts with the account:", deployer.address);
const MyToken = await ethers.getContractFactory("MyToken");
const myToken = await MyToken.deploy("MyToken", "MTK", ethers.utils.parseUnits("1000000", 18));
console.log("MyToken deployed to:", myToken.address);
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});
- getSigners: Retrieves the list of accounts provided by the Ethereum node, with the first account used as the deployer.
- getContractFactory: Gets the contract to deploy.
- deploy: Deploys the contract with the specified parameters (name, symbol, and initial supply).
- parseUnits: Converts the initial supply to the correct units, considering the token’s decimals.