Skip to content

Commit

Permalink
fix: add getNetworkName to hardhat environment
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyar committed Feb 10, 2025
1 parent 1152ad4 commit e2aafe2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .eslinttsconfigrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "./tsconfig.json",
"include": ["deploy", "hardhat.config.ts", "subgraphs"]
"include": ["deploy", "hardhat.config.ts", "subgraphs", "type-extensions.ts"]
}
6 changes: 5 additions & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import 'hardhat-deploy';
import "@nomicfoundation/hardhat-chai-matchers";
import "@nomiclabs/hardhat-ethers";
import 'hardhat-dependency-compiler';
import { HardhatUserConfig } from 'hardhat/config';
import { HardhatUserConfig, extendEnvironment } from "hardhat/config";

extendEnvironment(hre => {
hre.getNetworkName = () => process.env.HARDHAT_FORK_NETWORK || hre.network.name;
});

const compilers = {
compilers: [
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"esModuleInterop": true,
"resolveJsonModule": true
},
"include": ["subgraphs", "hardhat.config.ts"]
"include": ["subgraphs", "hardhat.config.ts", "type-extensions.ts"]
}
9 changes: 9 additions & 0 deletions type-extensions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'hardhat/types/runtime';

declare module 'hardhat/types/runtime' {
// This is an example of an extension to the Hardhat Runtime Environment.
// This new field will be available in tasks' actions, scripts, and tests.
export interface HardhatRuntimeEnvironment {
getNetworkName: () => string;
}
}

0 comments on commit e2aafe2

Please sign in to comment.