How set hardhat defender api keys using secrets.json

:computer: Environment

:memo:Details

:1234: Code to reproduce *
/
*

    // hardhat.config.js
    const { alchemyApiKey, mnemonic } = require('./secrets.json');
    require("@nomiclabs/hardhat-waffle");
    require("@nomiclabs/hardhat-truffle5");
    require('@openzeppelin/hardhat-upgrades');
    require('@nomiclabs/hardhat-solhint');
    require('@openzeppelin/hardhat-defender');
    require('solidity-coverage');
    require('hardhat-gas-reporter');
  const enableProduction = process.env.COMPILE_MODE === 'production';


    // This is a sample Hardhat task. To learn how to create your own go to
    // https://hardhat.org/guides/create-task.html
    task("accounts", "Prints the list of accounts", async () => {
      const accounts = await ethers.getSigners();

      for (const account of accounts) {
        console.log(account.address);
      }
    });

    // You need to export an object to set up your config
    // Go to https://hardhat.org/config/ to learn more

    /**
     * @type import('hardhat/config').HardhatUserConfig
     */
    module.exports = {
      defender: {
        apiKey: process.env.API_DEFENDER_KEY,
        apiSecret: process.env.API_DEFENDER_SECRET,
      },
      solidity: "0.7.6",
      networks: {
        hardhat: {
          blockGasLimit: 10000000,
        },
          gasReporter: {
        enable: enableGasReport,
        currency: 'USD',
        outputFile: process.env.CI ? 'gas-report.txt' : undefined,
      },
        rinkeby: {
          url: `https://eth-rinkeby.alchemyapi.io/v2/${alchemyApiKey}`,
          accounts: {mnemonic: mnemonic}
        }
      }
    };

*:1234: Code to reproduce for hardhat *

1 Like

Hi @Guard_Colombia,

You could use .env (https://github.com/motdotla/dotenv) or you could change the above to use values from a secrets.json.

const { alchemyApiKey, mnemonic,  defenderApiKey, defenderApiSecret} = require('./secrets.json');
...
        apiKey: defenderApiKey,
        apiSecret: defenderApiSecret,