deploy_evm_contract.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. const parser = yargs(hideBin(process.argv))
  8. .scriptName("deploy_evm_contract.ts")
  9. .usage(
  10. "Usage: $0 --std-output <path/to/std-output.json> --private-key <private-key> --chain <chain> [--deploy-args <arg> [... <args>]]"
  11. )
  12. .options({
  13. "std-output": {
  14. type: "string",
  15. demandOption: true,
  16. desc: "Path to the standard JSON output of the contract (build artifact)",
  17. },
  18. "private-key": {
  19. type: "string",
  20. demandOption: true,
  21. desc: "Private key to use for the deployment",
  22. },
  23. chain: {
  24. type: "string",
  25. demandOption: true,
  26. desc: "Chain to upload the contract on. Can be one of the evm chains available in the store",
  27. },
  28. "deploy-args": {
  29. type: "array",
  30. desc: "Arguments to pass to the contract constructor. Each argument must begin with 0x if it's a hex string",
  31. },
  32. });
  33. async function main() {
  34. const argv = await parser.argv;
  35. const chain = DefaultStore.chains[argv.chain];
  36. if (!chain) {
  37. throw new Error(`Chain ${argv.contract} not found`);
  38. }
  39. if (chain instanceof EvmChain) {
  40. const artifact = JSON.parse(readFileSync(argv["std-output"], "utf8"));
  41. const address = await chain.deploy(
  42. toPrivateKey(argv["private-key"]),
  43. artifact["abi"],
  44. artifact["bytecode"],
  45. argv["deploy-args"] || []
  46. );
  47. console.log(`Deployed contract at ${address}`);
  48. } else {
  49. throw new Error("Chain is not an EVM chain");
  50. }
  51. }
  52. main();