From 20e90ff289b893d675ee8331a4ff259140506016 Mon Sep 17 00:00:00 2001 From: Marko Date: Wed, 4 Dec 2024 16:02:19 +0100 Subject: [PATCH] add contracts tool --- tasks/contracts.ts | 30 ++++++++++++++++++++++++++++++ tasks/index.ts | 1 + 2 files changed, 31 insertions(+) create mode 100644 tasks/contracts.ts diff --git a/tasks/contracts.ts b/tasks/contracts.ts new file mode 100644 index 00000000..804ae256 --- /dev/null +++ b/tasks/contracts.ts @@ -0,0 +1,30 @@ +import { task } from 'hardhat/config'; +import fs from 'fs'; +import path from 'path'; + +task('contracts', 'Display contract deployment information') + .addParam('target', 'Network type (main or test)') + .setAction(async (taskArgs: { target: string }) => { + const networkType = taskArgs.target.toLowerCase(); + + if (networkType !== 'main' && networkType !== 'test') { + throw new Error('Network parameter must be either "main" or "test"'); + } + + const fileName = networkType === 'main' ? 'mainnet_deployed.json' : 'testnet_deployed.json'; + + // Read JSON file + const filePath = path.join(__dirname, '..', fileName); + const fileContent = fs.readFileSync(filePath, 'utf8'); + const deploymentData = JSON.parse(fileContent); + + // Extract and display contract information + console.log(`\nDeployed Contracts (${networkType})`); + console.log('========================'); + + Object.entries(deploymentData.contracts).forEach(([name, data]: [string, any]) => { + console.log(`\n${name}:`); + console.log(`Address: ${data.address}`); + console.log(`Explorer: ${data.url}`); + }); + }); diff --git a/tasks/index.ts b/tasks/index.ts index 954284e2..f8d7b03b 100644 --- a/tasks/index.ts +++ b/tasks/index.ts @@ -1,2 +1,3 @@ export * from './signatures'; export * from './copybatch'; +export * from './contracts';