Skip to content

Commit

Permalink
Add httpHeaders with auth-key not only for forking network
Browse files Browse the repository at this point in the history
  • Loading branch information
zZoMROT committed Dec 21, 2023
1 parent 1bf71c7 commit e872939
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions hardhat-setup/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ export function getNetwork(): string {
export class Networks {
networks: NetworksUserConfig = {};
etherscan: Etherscan = { apiKey: {}, customChains: [] };
authKeyHttpHeader?: string;

constructor(useHardhat: boolean = true, forkingNetworkName?: string, needAuthKeyHttpHeader: boolean = false, saveHardhatDeployments: boolean = false) {
constructor(useHardhat: boolean = true, forkingNetworkName?: string, authKeyHttpHeaderEnvVar?: string, saveHardhatDeployments: boolean = false) {
dotenv.config();
this.updateHardhatNetwork(useHardhat, forkingNetworkName, needAuthKeyHttpHeader, saveHardhatDeployments);
this.authKeyHttpHeader = !authKeyHttpHeaderEnvVar ? undefined : process.env[authKeyHttpHeaderEnvVar] || '';
this.updateHardhatNetwork(useHardhat, forkingNetworkName, this.authKeyHttpHeader, saveHardhatDeployments);
}

updateHardhatNetwork(useHardhat: boolean, forkingNetworkName?: string, needAuthKeyHttpHeader: boolean = false, saveHardhatDeployments: boolean = false) {
setAuthKeyHttpHeader(authKeyHttpHeaderEnvVar?: string) {
this.authKeyHttpHeader = !authKeyHttpHeaderEnvVar ? undefined : process.env[authKeyHttpHeaderEnvVar] || '';
}

updateHardhatNetwork(useHardhat: boolean, forkingNetworkName?: string, authKeyHttpHeader?: string, saveHardhatDeployments: boolean = false) {
if (useHardhat || forkingNetworkName) {
this.networks.hardhat = {
chainId: Number(process.env.FORK_CHAIN_ID) || 31337,
Expand All @@ -31,9 +37,7 @@ export class Networks {
if (forkingNetworkName) {
this.networks.hardhat!.forking = {
url: process.env[`${forkingNetworkName.toUpperCase()}_RPC_URL`] || '',
httpHeaders: needAuthKeyHttpHeader
? { 'auth-key': process.env.RPC_AUTH_HEADER || '' }
: undefined,
httpHeaders: authKeyHttpHeader ? { 'auth-key': authKeyHttpHeader } : undefined,
};
}
}
Expand All @@ -42,6 +46,7 @@ export class Networks {
if (url && privateKey && etherscanNetworkName && etherscanKey) {
this.networks[name] = {
url,
httpHeaders: this.authKeyHttpHeader ? { 'auth-key': this.authKeyHttpHeader } : undefined,
chainId,
accounts: [privateKey],
hardfork,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@1inch/solidity-utils",
"version": "3.5.5",
"version": "3.5.6",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"exports": {
Expand Down

0 comments on commit e872939

Please sign in to comment.