@@ -14,7 +14,7 @@ const parser = yargs(hideBin(process.argv))
14
14
"std-output" : {
15
15
type : "string" ,
16
16
demandOption : true ,
17
- desc : "Path to the standard output of the contract (build artifact)" ,
17
+ desc : "Path to the standard JSON output of the contract (build artifact)" ,
18
18
} ,
19
19
"private-key" : {
20
20
type : "string" ,
@@ -28,23 +28,32 @@ const parser = yargs(hideBin(process.argv))
28
28
} ,
29
29
"deploy-args" : {
30
30
type : "array" ,
31
- desc : "Arguments to pass to the contract constructor" ,
31
+ desc : "Arguments to pass to the contract constructor. Each argument must begin with 0x if it's a hex string " ,
32
32
} ,
33
33
} ) ;
34
34
35
35
async function main ( ) {
36
36
const argv = await parser . argv ;
37
37
38
- const chain = DefaultStore . chains [ argv . chain ] as EvmChain ;
39
- const artifact = JSON . parse ( readFileSync ( argv [ "std-output" ] , "utf8" ) ) ;
40
- const address = await chain . deploy (
41
- toPrivateKey ( argv [ "private-key" ] ) ,
42
- artifact [ "abi" ] ,
43
- artifact [ "bytecode" ] ,
44
- argv [ "deploy-args" ] || [ ]
45
- ) ;
38
+ const chain = DefaultStore . chains [ argv . chain ] ;
46
39
47
- console . log ( `Deployed contract at ${ address } ` ) ;
40
+ if ( ! chain ) {
41
+ throw new Error ( `Chain ${ argv . contract } not found` ) ;
42
+ }
43
+
44
+ if ( chain instanceof EvmChain ) {
45
+ const artifact = JSON . parse ( readFileSync ( argv [ "std-output" ] , "utf8" ) ) ;
46
+ const address = await chain . deploy (
47
+ toPrivateKey ( argv [ "private-key" ] ) ,
48
+ artifact [ "abi" ] ,
49
+ artifact [ "bytecode" ] ,
50
+ argv [ "deploy-args" ] || [ ]
51
+ ) ;
52
+
53
+ console . log ( `Deployed contract at ${ address } ` ) ;
54
+ } else {
55
+ throw new Error ( "Chain is not an EVM chain" ) ;
56
+ }
48
57
}
49
58
50
59
main ( ) ;
0 commit comments