Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/wise-bats-wish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,15 @@ console.log(hardhatConfig.etherscan());

### hardhatConfig.getEnvVariableNames()

Returns an API key required for Etherscan V2 contract verification API and a single `MNEMONIC` variable that can be used to configure all networks.
Returns environment variable names that are expected to be set for Hardhat configuration.

```ts
import { hardhatConfig } from '@api3/contracts';
console.log(hardhatConfig.getEnvVariableNames());
/*
[
'MNEMONIC',
'KEYCARD_ACCOUNT',
'ETHERSCAN_API_KEY',
'HARDHAT_HTTP_RPC_URL_APECHAIN_ARBITRUM_SEPOLIA_TESTNET',
...
Expand Down
7 changes: 6 additions & 1 deletion deploy/1_deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,12 @@ module.exports = async () => {
api3ReaderProxyV1Metadata
);
if ((await ethers.provider.getCode(expectedApi3ReaderProxyV1Address)) === '0x') {
await api3ReaderProxyV1Factory.deployApi3ReaderProxyV1(dapiName, dappId, api3ReaderProxyV1Metadata);
const proxyTransactionResponse = await api3ReaderProxyV1Factory.deployApi3ReaderProxyV1(
dapiName,
dappId,
api3ReaderProxyV1Metadata
);
await proxyTransactionResponse.wait(1);
log(`Deployed example Api3ReaderProxyV1 at ${expectedApi3ReaderProxyV1Address}`);
}

Expand Down
1 change: 1 addition & 0 deletions example.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
MNEMONIC=
KEYCARD_ACCOUNT=
ETHERSCAN_API_KEY=
1 change: 1 addition & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as fs from 'node:fs';
import { glob } from 'glob';
import type { HardhatUserConfig } from 'hardhat/config';
import '@nomicfoundation/hardhat-toolbox';
import 'keycard-hardhat-provider';
import 'hardhat-deploy';
import 'dotenv/config';
import { task } from 'hardhat/config';
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"hardhat": "^2.26.2",
"hardhat-deploy": "1.0.2",
"hardhat-gas-reporter": "^2.3.0",
"keycard-hardhat-provider": "^0.1.1",
"jest": "^30.0.5",
"prettier": "^3.5.3",
"prettier-plugin-solidity": "^2.0.0",
Expand Down
39 changes: 35 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion scripts/check-example-env-file.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from 'node:fs';

const expectedEnvVars = ['MNEMONIC', 'ETHERSCAN_API_KEY'];
const expectedEnvVars = ['MNEMONIC', 'KEYCARD_ACCOUNT', 'ETHERSCAN_API_KEY'];
const expectedExampleEnvFileContents = expectedEnvVars.reduce((fileContents: string, envVariableName: string) => {
return `${fileContents}${envVariableName}=\n`;
}, '');
Expand Down
2 changes: 1 addition & 1 deletion src/hardhat-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe(getEnvVariableNames.name, () => {
it('returns an array with expected env variables', () => {
const apiKeyEnvName = etherscanApiKeyName();
const networkRpcUrlNames = CHAINS.map((chain) => networkHttpRpcUrlName(chain));
const expected = ['MNEMONIC', apiKeyEnvName, ...networkRpcUrlNames];
const expected = ['MNEMONIC', 'KEYCARD_ACCOUNT', apiKeyEnvName, ...networkRpcUrlNames];
expect(getEnvVariableNames()).toStrictEqual(expected);
});
});
Expand Down
8 changes: 6 additions & 2 deletions src/hardhat-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function getEnvVariableNames(): string[] {

const networkRpcUrlNames = CHAINS.map((chain) => networkHttpRpcUrlName(chain));

return ['MNEMONIC', apiKeyEnvName, ...networkRpcUrlNames];
return ['MNEMONIC', 'KEYCARD_ACCOUNT', apiKeyEnvName, ...networkRpcUrlNames];
}

export function etherscanApiKeyName(): string {
Expand Down Expand Up @@ -77,12 +77,16 @@ export function networks(): HardhatNetworksConfig {
throw new Error('Cannot be called outside of a Node.js environment');
}

const credentials = process.env.KEYCARD_ACCOUNT
? { keycardAccount: process.env.KEYCARD_ACCOUNT }
: { accounts: { mnemonic: process.env.MNEMONIC ?? '' } };

return CHAINS.reduce((networks, chain) => {
const defaultProvider = chain.providers.find((p) => p.alias === 'default');
const overrides = chain.hardhatConfigOverrides?.networks ?? {};

networks[chain.alias] = {
accounts: { mnemonic: process.env.MNEMONIC ?? '' },
...credentials,
chainId: Number(chain.id),
url: process.env[networkHttpRpcUrlName(chain)] ?? defaultProvider!.rpcUrl!,
...overrides,
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ export type ChainProvider = z.infer<typeof chainProviderSchema>;

export interface HardhatNetworksConfig {
[key: string]: {
accounts: { mnemonic: string };
accounts?: { mnemonic: string };
keycardAccount?: string;
chainId: number;
url: string;
};
Expand Down
Loading