Skip to content

Commit 39df9a2

Browse files
committed
feat(contract_manager): add a script to deploy evm contract
1 parent 6f3dd5c commit 39df9a2

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import yargs from "yargs";
2+
import { hideBin } from "yargs/helpers";
3+
import { EvmChain } from "../src/chains";
4+
import { DefaultStore } from "../src/store";
5+
import { readFileSync } from "fs";
6+
import { toPrivateKey } from "../src";
7+
8+
const parser = yargs(hideBin(process.argv))
9+
.scriptName("deploy_evm_contract.ts")
10+
.usage(
11+
"Usage: $0 --code <path/to/std-output.json> --private-key <private-key> --chain <chain> [--deploy-args <arg> [... <args>]]"
12+
)
13+
.options({
14+
"std-output": {
15+
type: "string",
16+
demandOption: true,
17+
desc: "Path to the standard output of the contract (build artifact)",
18+
},
19+
"private-key": {
20+
type: "string",
21+
demandOption: true,
22+
desc: "Private key to use for the deployment",
23+
},
24+
chain: {
25+
type: "string",
26+
demandOption: true,
27+
desc: "Chain to upload the contract on. Can be one of the evm chains available in the store",
28+
},
29+
"deploy-args": {
30+
type: "array",
31+
desc: "Arguments to pass to the contract constructor",
32+
},
33+
});
34+
35+
async function main() {
36+
const argv = await parser.argv;
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+
);
46+
47+
console.log(`Deployed contract at ${address}`);
48+
}
49+
50+
main();

0 commit comments

Comments
 (0)