Skip to content

Commit e3143cb

Browse files
committed
Improve deploy script
1 parent 7c0a7cc commit e3143cb

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

deploy.js

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
const HDWalletProvider = require("@truffle/hdwallet-provider");
22
const Web3 = require("web3");
3+
const fs = require("fs")
34

45
const { abi, bytecode } = require("./compile");
6+
const path = require("path");
57

68
const provider = new HDWalletProvider(
79
process.env.ETH_MNEMONIC,
@@ -10,17 +12,34 @@ const provider = new HDWalletProvider(
1012
const web3 = new Web3(provider);
1113

1214
const deploy = async () => {
15+
console.log("Obtaining available accounts");
1316
const accounts = await web3.eth.getAccounts();
17+
console.log("Successfully obtained " + accounts.length + " accounts");
18+
19+
console.log("Reading account balance before starting...");
20+
const balance = await web3.eth.getBalance(accounts[0]);
21+
console.log("Your balance is " + balance + " wei");
1422

1523
console.log("Attempting to deploy from account", accounts[0]);
1624

1725
const result = await new web3.eth.Contract(abi)
18-
.deploy({ data: bytecode, arguments: ["Hi there"]})
19-
.send({ gas: "1000000", from: accounts[0] });
26+
.deploy({ data: bytecode, arguments: []})
27+
.send({ gas: "10000000", from: accounts[0] });
28+
29+
console.log("Storing contract ABI in abi.json");
30+
31+
fs.writeFileSync(
32+
path.resolve(__dirname, "abi.json"),
33+
JSON.stringify(abi)
34+
);
35+
36+
console.log("Successfully saved ABI");
37+
2038

2139
console.log("Contract deployed to ", result.options.address);
2240

2341
provider.engine.stop();
2442
}
2543

44+
console.log("Starting deployment...");
2645
deploy();

0 commit comments

Comments
 (0)