|
1 | 1 | import '@nomicfoundation/hardhat-viem';
|
2 | 2 | import hre from 'hardhat';
|
3 |
| -import { Account, getContract } from 'viem'; |
| 3 | +import { Account, getContract } from 'viem'; |
4 | 4 | import { anvil } from 'viem/chains';
|
| 5 | +import dotenv from 'dotenv'; |
| 6 | +import yargs from 'yargs'; |
| 7 | + |
| 8 | +dotenv.config(); |
5 | 9 |
|
6 | 10 | // anvil
|
7 | 11 | // 別のターミナルを開く
|
8 | 12 | // pnpm hardhat test src/tests/jpyc-tests/jpyc-balance2.test.ts --network localhost
|
| 13 | +const argv = yargs(process.argv.slice(2)) |
| 14 | + .option('minterAddress', { |
| 15 | + type: 'string', |
| 16 | + description: 'Address of the minter' |
| 17 | + }) |
| 18 | + .option('toAddress', { |
| 19 | + type: 'string', |
| 20 | + description: 'Address to mint tokens to' |
| 21 | + }) |
| 22 | + .option('amount', { |
| 23 | + type: 'number', |
| 24 | + description: 'Amount of tokens to mint' |
| 25 | + }) |
| 26 | + .argv; |
| 27 | + |
9 | 28 |
|
10 | 29 | let JPYC_ADMIN_ACCOUNT: Account;
|
11 |
| -(async () => { |
| 30 | + |
| 31 | +async function initializeAdminAccount() { |
12 | 32 | const [jpycAdmin] = await hre.viem.getWalletClients({
|
13 | 33 | chain: anvil
|
14 |
| - }) |
| 34 | + }); |
15 | 35 | JPYC_ADMIN_ACCOUNT = jpycAdmin.account;
|
16 |
| -})(); |
| 36 | +} |
17 | 37 |
|
18 | 38 | async function deployJpyc() {
|
19 | 39 | const jpycImpl = await hre.viem.deployContract("FiatTokenV1", []);
|
@@ -85,19 +105,23 @@ async function mintTokens(jpyc: any, minterAddress: string, toAddress: string, a
|
85 | 105 |
|
86 | 106 | //デプロイ用、mint用のスクリプト to addressの指定をお願いします。
|
87 | 107 | async function main() {
|
| 108 | + await initializeAdminAccount(); |
88 | 109 | const { jpyc } = await deployJpyc();
|
89 | 110 | const symbol = await jpyc.read.symbol();
|
90 | 111 | const name = await jpyc.read.name();
|
91 |
| - const minterAddress = await jpyc.read.minter(); |
92 |
| - const toAddress = ""; |
| 112 | + |
| 113 | + const minterAddress = argv.minterAddress || process.env.MINTER_ADDRESS || JPYC_ADMIN_ACCOUNT.address; |
| 114 | + const toAddress = argv.toAddress || process.env.TO_ADDRESS || "0x70997970C51812dc3A010C7d01b50e0d17dc79C8"; |
| 115 | + const amount = BigInt(argv.amount || process.env.MINT_AMOUNT || 1000000); |
93 | 116 |
|
94 | 117 |
|
95 |
| - await mintTokens(jpyc,minterAddress as string, toAddress, 1000000n); |
| 118 | + await mintTokens(jpyc,minterAddress as string, toAddress, amount); |
96 | 119 |
|
97 | 120 | console.log("token deployed:", jpyc.address);
|
98 | 121 | console.log("token symbol:", symbol);
|
99 | 122 | console.log("token name:", name);
|
100 | 123 | console.log("to address:",toAddress);
|
| 124 | + console.log("to address balance:",await jpyc.read.balanceOf([toAddress])); |
101 | 125 |
|
102 | 126 | }
|
103 | 127 |
|
|
0 commit comments