Skip to content

Commit

Permalink
feat: improve deploy script and support loose private keys
Browse files Browse the repository at this point in the history
  • Loading branch information
petejkim committed Apr 5, 2022
1 parent 4c37963 commit d7a1e9e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
31 changes: 17 additions & 14 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { resolve } from "path";

import { config as dotenvConfig } from "dotenv";
import { HardhatUserConfig } from "hardhat/config";
import { NetworkUserConfig } from "hardhat/types";
import { HttpNetworkUserConfig } from "hardhat/types";

dotenvConfig({ path: resolve(__dirname, "./.env") });

Expand All @@ -22,9 +22,11 @@ const chainIds = {
};

// Ensure that we have all the environment variables we need.
let mnemonic: string | undefined = process.env.MNEMONIC;
if (!mnemonic) {
console.warn("MNEMONIC is not set in the .env file");
let mnemonic: string = process.env.MNEMONIC || "";
const privateKey: string = process.env.PRIVATE_KEY || "";

if (!mnemonic && !privateKey) {
console.warn("neither MNEMONIC nor PRIVATE_KEY is not set in the .env file");
mnemonic =
"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
}
Expand All @@ -36,17 +38,18 @@ if (!infuraApiKey) {

const etherscanApiKey: string | undefined = process.env.ETHERSCAN_API_KEY;

function getChainConfig(network: keyof typeof chainIds): NetworkUserConfig {
function getChainConfig(network: keyof typeof chainIds): HttpNetworkUserConfig {
const url: string = "https://" + network + ".infura.io/v3/" + infuraApiKey;
return {
accounts: {
count: 10,
mnemonic,
path: "m/44'/60'/0'/0",
},
accounts: privateKey
? [privateKey]
: {
count: 10,
mnemonic,
path: "m/44'/60'/0'/0",
},
chainId: chainIds[network],
url,
minGasPrice: 2e9,
};
}

Expand All @@ -60,9 +63,9 @@ const config: HardhatUserConfig = {
},
networks: {
hardhat: {
accounts: {
mnemonic,
},
accounts: privateKey
? [{ privateKey, balance: "100000000000000000000" }]
: { mnemonic },
chainId: chainIds.hardhat,
},
goerli: getChainConfig("goerli"),
Expand Down
9 changes: 7 additions & 2 deletions src/scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ async function main() {
const iCoinbaseResolver = CoinbaseResolver__factory.createInterface();
const constructorData = iCoinbaseResolver.encodeDeploy(constructorArgs);

console.log(`deploying CoinbaseResolver (arguments: ${constructorData})...`);
console.log(
"Deploying CoinbaseResolver...\n\n" +
`Constructor arguments:\n${JSON.stringify(constructorArgs)}\n\n` +
`Constructor calldata:\n${constructorData}\n`
);

const implementation = await resolverFactory.deploy(...constructorArgs);
await implementation.deployed();
console.log(
"-> deployed CoinbaseResolver contract at",
"-> Deployed CoinbaseResolver contract at",
implementation.address
);
}
Expand Down

0 comments on commit d7a1e9e

Please sign in to comment.