|
| 1 | +import assert from 'assert' |
| 2 | + |
| 3 | +import { type DeployFunction } from 'hardhat-deploy/types' |
| 4 | + |
| 5 | +const contractName = 'MyERC20Mock' |
| 6 | + |
| 7 | +const deploy: DeployFunction = async (hre) => { |
| 8 | + const { getNamedAccounts, deployments } = hre |
| 9 | + |
| 10 | + const { deploy } = deployments |
| 11 | + const { deployer } = await getNamedAccounts() |
| 12 | + |
| 13 | + assert(deployer, 'Missing named deployer account') |
| 14 | + |
| 15 | + console.log(`Network: ${hre.network.name}`) |
| 16 | + console.log(`Deployer: ${deployer}`) |
| 17 | + |
| 18 | + // Token configuration |
| 19 | + const tokenName = 'My ERC20 Mock' |
| 20 | + const tokenSymbol = 'MERC20' |
| 21 | + const initialMintAmount = hre.ethers.utils.parseEther('10') // 10 tokens |
| 22 | + |
| 23 | + const { address } = await deploy(contractName, { |
| 24 | + from: deployer, |
| 25 | + args: [ |
| 26 | + tokenName, // Token name |
| 27 | + tokenSymbol, // Token symbol |
| 28 | + ], |
| 29 | + log: true, |
| 30 | + skipIfAlreadyDeployed: false, |
| 31 | + }) |
| 32 | + |
| 33 | + console.log(`Deployed contract: ${contractName}, network: ${hre.network.name}, address: ${address}`) |
| 34 | + console.log(`Token: ${tokenName} (${tokenSymbol})`) |
| 35 | + |
| 36 | + // Mint initial tokens to the deployer |
| 37 | + const [signer] = await hre.ethers.getSigners() |
| 38 | + const mintBurnToken = await hre.ethers.getContractAt(contractName, address, signer) |
| 39 | + |
| 40 | + const mintTx = await mintBurnToken.mint(deployer, initialMintAmount) |
| 41 | + await mintTx.wait() |
| 42 | + |
| 43 | + const balance = await mintBurnToken.balanceOf(deployer) |
| 44 | + console.log(`Minted ${hre.ethers.utils.formatEther(balance)} ${tokenSymbol} tokens to deployer: ${deployer}`) |
| 45 | +} |
| 46 | + |
| 47 | +deploy.tags = [contractName] |
| 48 | + |
| 49 | +export default deploy |
0 commit comments