21 lines
926 B
TypeScript
21 lines
926 B
TypeScript
import { task } from "hardhat/config";
|
|
import { HardhatRuntimeEnvironment } from "hardhat/types";
|
|
import path from "path";
|
|
import fs from "fs";
|
|
import config from "../hardhat.config";
|
|
|
|
export const getDeployedContractAddress = async (hre: HardhatRuntimeEnvironment, contractName: string, network: string) => {
|
|
const chainId = config.networks?.[network]?.chainId;
|
|
if (!chainId) {
|
|
throw new Error(`Chain ID for network ${network} not found in hardhat.config.ts`);
|
|
}
|
|
const artifactsPath = path.join(__dirname, `../ignition/deployments/chain-${chainId}/deployed_addresses.json`);
|
|
const deploymentData = JSON.parse(fs.readFileSync(artifactsPath, 'utf8'));
|
|
const deployedAddress = deploymentData[`${contractName}#${contractName}`];
|
|
|
|
if (!deployedAddress) {
|
|
throw new Error(`Contract ${contractName} not found in deployment data for network ${network}`);
|
|
}
|
|
return deployedAddress as `0x${string}` | null;
|
|
}
|