forked from UMAprotocol/emp-tools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchain.ts
54 lines (46 loc) · 1.27 KB
/
chain.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
require("dotenv").config();
import Ganache from "ganache-core";
import { ethers } from "ethers";
import { getDai } from "./utils/getDai";
const port = 8545;
// Required environment variables.
const nodeUrl = process.env.MAINNET_NODE_URL;
if (!nodeUrl) {
throw new Error(
`Set a "MAINNET_NODE_URL" in your .env from which to fork from`
);
}
// Optional environment variables.
const privKey = process.env.PRIV_KEY;
// start server
const server = Ganache.server({
fork: nodeUrl,
network_id: 1,
gasLimit: 20000000,
accounts: [
{
secretKey: privKey,
balance: ethers.utils.hexlify(ethers.utils.parseEther("1000")),
},
],
});
// listen and run post-launch code
server.listen(port, async (err: any) => {
if (err) {
console.error(err);
} else {
console.log(`Forked off of node: ${nodeUrl}\n`);
console.log(`Test private key:\n`);
console.log(`\t${privKey}`);
console.log(`\nTest chain started on port ${port}, listening...`);
// retrieve some DAI from Uniswap
if (privKey) {
const provider = new ethers.providers.JsonRpcProvider();
const wallet = new ethers.Wallet(privKey);
await getDai(wallet.connect(provider));
} else {
console.log(`No "PRIV_KEY" specified to mint DAI to`);
}
}
});
export {};