-
Notifications
You must be signed in to change notification settings - Fork 937
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make it work with a script to load env vars
- Loading branch information
Showing
6 changed files
with
63 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import * as dotenv from "dotenv"; | ||
dotenv.config(); | ||
import { Wallet } from "ethers"; | ||
import password from "@inquirer/password"; | ||
import { spawn } from "child_process"; | ||
|
||
/** | ||
* Unencrypts the private key and runs the hardhat deploy command | ||
*/ | ||
async function main() { | ||
const isNetworkProvided = process.argv.slice(2).includes("--network"); | ||
|
||
if (!isNetworkProvided) { | ||
// Deploy command on the localhost network | ||
const hardhat = spawn("hardhat", ["deploy", ...process.argv.slice(2)], { | ||
stdio: "inherit", | ||
env: process.env, | ||
}); | ||
|
||
hardhat.on("exit", code => { | ||
process.exit(code || 0); | ||
}); | ||
return; | ||
} | ||
|
||
const encryptedKey = process.env.DEPLOYER_PRIVATE_KEY_ENCRYPTED; | ||
|
||
if (!encryptedKey) { | ||
console.log("🚫️ You don't have a deployer account. Run `yarn generate` first"); | ||
return; | ||
} | ||
|
||
const pass = await password({ message: "Enter password to decrypt private key:", mask: true }); | ||
|
||
try { | ||
const wallet = await Wallet.fromEncryptedJson(encryptedKey, pass); | ||
process.env.DEPLOYER_PRIVATE_KEY = wallet.privateKey; | ||
|
||
const hardhat = spawn("hardhat", ["deploy", ...process.argv.slice(2)], { | ||
stdio: "inherit", | ||
env: process.env, | ||
}); | ||
|
||
hardhat.on("exit", code => { | ||
process.exit(code || 0); | ||
}); | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
} catch (e) { | ||
console.error("Failed to decrypt private key. Wrong password?"); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
main().catch(console.error); |