From c83e840222e48cb1118182ca8501b9a6637ba53e Mon Sep 17 00:00:00 2001 From: coolcode Date: Mon, 29 Jan 2024 21:07:24 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A5=91=20task?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hardhat.config.ts | 6 +----- tasks/Balance.ts | 24 +++++++++++------------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/hardhat.config.ts b/hardhat.config.ts index 70b6bc3..3822b6d 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -4,11 +4,7 @@ import "@nomicfoundation/hardhat-toolbox" import "@typechain/hardhat" import { HardhatUserConfig, task } from "hardhat/config" -import Balance from "./tasks/Balance" - -task("balance", "Prints an account's balance") - .addParam("account", "The account's address") - .setAction(Balance) +import "./tasks/Balance" const config: HardhatUserConfig = { solidity: { diff --git a/tasks/Balance.ts b/tasks/Balance.ts index d9c9e41..5898fad 100644 --- a/tasks/Balance.ts +++ b/tasks/Balance.ts @@ -1,15 +1,13 @@ -import { HardhatRuntimeEnvironment } from "hardhat/types/runtime" +import { task } from "hardhat/config" -export default async ( - params: { account: string }, - hre: HardhatRuntimeEnvironment -): Promise => { - const ethers = hre.ethers - const accountIndex = params.account - console.info("account index:", accountIndex) - const accounts = await ethers.getSigners() - const address = await accounts[accountIndex].getAddress() - const balance = await ethers.provider.getBalance(address) +task("balance", "Prints an account's balance") + .addParam("account", "The account's address") + .setAction(async (taskArgs, { ethers }) => { + const accountIndex = taskArgs.account + console.info("account index:", accountIndex) + const accounts = await ethers.getSigners() + const address = await accounts[accountIndex].getAddress() + const balance = await ethers.provider.getBalance(address) - console.info(`Balance account ${address}: ${balance}`) -} \ No newline at end of file + console.info(`Balance account ${address}: ${balance}`) + }) \ No newline at end of file