1
1
const HDWalletProvider = require ( "@truffle/hdwallet-provider" ) ;
2
2
const Web3 = require ( "web3" ) ;
3
+ const fs = require ( "fs" )
3
4
4
5
const { abi, bytecode } = require ( "./compile" ) ;
6
+ const path = require ( "path" ) ;
5
7
6
8
const provider = new HDWalletProvider (
7
9
process . env . ETH_MNEMONIC ,
@@ -10,17 +12,34 @@ const provider = new HDWalletProvider(
10
12
const web3 = new Web3 ( provider ) ;
11
13
12
14
const deploy = async ( ) => {
15
+ console . log ( "Obtaining available accounts" ) ;
13
16
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" ) ;
14
22
15
23
console . log ( "Attempting to deploy from account" , accounts [ 0 ] ) ;
16
24
17
25
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
+
20
38
21
39
console . log ( "Contract deployed to " , result . options . address ) ;
22
40
23
41
provider . engine . stop ( ) ;
24
42
}
25
43
44
+ console . log ( "Starting deployment..." ) ;
26
45
deploy ( ) ;
0 commit comments