Skip to content

Commit db13b7b

Browse files
committed
address feedbacks
1 parent 39df9a2 commit db13b7b

File tree

2 files changed

+21
-12
lines changed

2 files changed

+21
-12
lines changed

contract_manager/scripts/deploy_evm_contract.ts

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const parser = yargs(hideBin(process.argv))
1414
"std-output": {
1515
type: "string",
1616
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)",
1818
},
1919
"private-key": {
2020
type: "string",
@@ -28,23 +28,32 @@ const parser = yargs(hideBin(process.argv))
2828
},
2929
"deploy-args": {
3030
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",
3232
},
3333
});
3434

3535
async function main() {
3636
const argv = await parser.argv;
3737

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];
4639

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+
}
4857
}
4958

5059
main();

contract_manager/src/chains.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ export class EvmChain extends Chain {
392392
* @param privateKey hex string of the 32 byte private key without the 0x prefix
393393
* @param abi the abi of the contract, can be obtained from the compiled contract json file
394394
* @param bytecode bytecode of the contract, can be obtained from the compiled contract json file
395-
* @param deployArgs arguments to pass to the constructor
395+
* @param deployArgs arguments to pass to the constructor. Each argument must begin with 0x if it's a hex string
396396
* @returns the address of the deployed contract
397397
*/
398398
async deploy(

0 commit comments

Comments
 (0)