-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.js
45 lines (32 loc) · 1.26 KB
/
deploy.js
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
const HDWalletProvider = require("@truffle/hdwallet-provider");
const Web3 = require("web3");
const fs = require("fs")
const { abi, bytecode } = require("./compile");
const path = require("path");
const provider = new HDWalletProvider(
process.env.ETH_MNEMONIC,
process.env.ETH_PROVIDER
);
const web3 = new Web3(provider);
const deploy = async () => {
console.log("Obtaining available accounts");
const accounts = await web3.eth.getAccounts();
console.log("Successfully obtained " + accounts.length + " accounts");
console.log("Reading account balance before starting...");
const balance = await web3.eth.getBalance(accounts[0]);
console.log("Your balance is " + balance + " wei");
console.log("Attempting to deploy from account", accounts[0]);
const result = await new web3.eth.Contract(abi)
.deploy({ data: bytecode, arguments: []})
.send({ gas: "10000000", from: accounts[0] });
console.log("Storing contract ABI in abi.json");
fs.writeFileSync(
path.resolve(__dirname, "abi.json"),
JSON.stringify(abi)
);
console.log("Successfully saved ABI");
console.log("Contract deployed to ", result.options.address);
provider.engine.stop();
}
console.log("Starting deployment...");
deploy();