|
1 | | -import { task } from 'hardhat/config'; |
| 1 | +import { task, types } from 'hardhat/config'; |
2 | 2 | import { HardhatRuntimeEnvironment } from 'hardhat/types'; |
3 | 3 |
|
4 | 4 | const ERC20_MOCK_CONTRACT_NAME = 'ERC20Mock'; |
5 | 5 |
|
6 | 6 | // Deploy the ERC20Mock contract |
7 | | -async function deployERC20Mock(hre: HardhatRuntimeEnvironment, name: string, symbol: string) { |
| 7 | +async function deployERC20Mock(hre: HardhatRuntimeEnvironment, name: string, symbol: string, decimals: number) { |
8 | 8 | const { getNamedAccounts, ethers, deployments, network } = hre; |
9 | 9 | const { save, getArtifact } = deployments; |
10 | 10 |
|
11 | 11 | const { deployer } = await getNamedAccounts(); |
12 | 12 | const deployerSigner = await ethers.getSigner(deployer); |
13 | 13 |
|
14 | 14 | const factory = await ethers.getContractFactory(ERC20_MOCK_CONTRACT_NAME, deployerSigner); |
15 | | - const contract = await factory.deploy(name, symbol); |
| 15 | + const contract = await factory.deploy(name, symbol, decimals); |
16 | 16 | await contract.waitForDeployment(); |
17 | 17 |
|
18 | 18 | const contractAddress = await contract.getAddress(); |
@@ -40,14 +40,15 @@ async function deployERC20Mock(hre: HardhatRuntimeEnvironment, name: string, sym |
40 | 40 |
|
41 | 41 | // Deploy the ERC20Mock contract |
42 | 42 | // Example usage: |
43 | | -// npx hardhat task:deployERC20Mock --name "Mock Token" --symbol "MTK" --network testnet |
| 43 | +// npx hardhat task:deployERC20Mock --name "Mock Token" --symbol "MTK" --decimals 18 --network testnet |
44 | 44 | task('task:deployERC20Mock') |
45 | 45 | .addParam('name', 'The name of the ERC20 token') |
46 | 46 | .addParam('symbol', 'The symbol of the ERC20 token') |
47 | | - .setAction(async function ({ name, symbol }, hre) { |
| 47 | + .addParam('decimals', 'The decimals of the ERC20 token', 18, types.int) |
| 48 | + .setAction(async function ({ name, symbol, decimals }, hre) { |
48 | 49 | console.log('Deploying ERC20Mock contract...\n'); |
49 | 50 |
|
50 | | - await deployERC20Mock(hre, name, symbol); |
| 51 | + await deployERC20Mock(hre, name, symbol, parseInt(decimals)); |
51 | 52 |
|
52 | 53 | console.log('✅ ERC20Mock contract deployed\n'); |
53 | 54 | }); |
0 commit comments