-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtasks.ts
97 lines (80 loc) · 3.52 KB
/
tasks.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// tasks
import { task, types } from "hardhat/config";
task("abi", "prints the ABI of a contract")
.addParam("contract", "contract path", undefined, types.inputFile, false)
.setAction(async ({ contract }, { ethers, artifacts, run }) => {
await run("compile");
// get contract fully qualified name
const allContracts = await artifacts.getAllFullyQualifiedNames()
const contractName = allContracts.find((e) => e.startsWith(contract)) || contract
// read contract
const contractArtifact = await artifacts.readArtifact(contractName)
const contractFactory = await ethers.getContractFactoryFromArtifact(contractArtifact) as any
const format = ethers.utils.FormatTypes.full // full minimal json
const abi = contractFactory.interface.format(format)
console.log(abi);
});
task("deploy", "deploys a contract")
.addParam("contract", "contract path", undefined, types.inputFile, false)
.addOptionalPositionalParam("arg0", "1st constructor argument")
.addOptionalPositionalParam("arg1", "2nd constructor argument")
.addOptionalPositionalParam("arg2", "3rd constructor argument")
.addOptionalPositionalParam("arg3", "4th constructor argument")
.addOptionalPositionalParam("arg4", "5th constructor argument")
.setAction(async (
{ contract, arg0, arg1, arg2, arg3, arg4 },
{ ethers, artifacts, run }
) => {
await run("compile");
const args = arg0 && (
arg1 && (
arg2 && (
arg3 && (
arg4 && (
[ arg0, arg1, arg2, arg3, arg4 ]
) || [ arg0, arg1, arg2, arg3 ]
) || [ arg0, arg1, arg2 ]
) || [ arg0, arg1 ]
) || [ arg0 ]
) || []
const allContracts = await artifacts.getAllFullyQualifiedNames()
const contractName = allContracts.find((e) => e.startsWith(contract)) || ""
console.log("Deploy started");
const contractDeployed = await ethers.deployContract(
contractName,
args
);
console.log(`Contract ${contract} deployed at address: `, contractDeployed.address);
await contractDeployed.deployTransaction.wait();
});
task("mnemonic", "Prints a new valid mnemonic to use instead of default one")
.setAction(async (_, { ethers }) => {
const { mnemonic: { phrase: mnemonicPhrase } } = ethers.Wallet.createRandom()
console.log(mnemonicPhrase);
}
)
// if config.networks.hardhat.accounts is set
// the private keys are not shown by the hardhat node
task("hardhat-account-infos", "Prints more informations about the accounts used by hardhat",
async ( _, hre) => {
const { accounts } = hre.config.networks.hardhat;
await hre.run("account-info", accounts)
});
// general use purpose
// you have a mnemonic and you want to get the accounts infos
task("account-info", "Prints the accounts informations from a mnemonic")
.addParam("mnemonic", "should be valid")
.addOptionalParam("count", "number of addresses to print", 20, types.int)
.addOptionalParam("path", "", "m/44'/60'/0'/0/")
.addOptionalParam("initialIndex", "first account index", 0, types.int)
.setAction(async ({ mnemonic, count, path, initialIndex, passphrase }, { ethers } ) => {
Array(count).fill(0).map((_, i) => {
const PATH = path + (i + initialIndex).toString()
const wallet = ethers.Wallet.fromMnemonic(mnemonic, PATH)
console.log("Mnemonic: ", wallet.mnemonic.phrase);
console.log("Address: ", wallet.address);
console.log("privateKey: ", wallet.privateKey);
console.log("publicKey: ", wallet.publicKey);
console.log("----------")
})
})