deploy_evm_contract.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* eslint-disable @typescript-eslint/no-floating-promises */
  2. /* eslint-disable @typescript-eslint/no-unsafe-argument */
  3. /* eslint-disable @typescript-eslint/no-unsafe-member-access */
  4. /* eslint-disable @typescript-eslint/no-unsafe-assignment */
  5. /* eslint-disable unicorn/prefer-top-level-await */
  6. /* eslint-disable no-console */
  7. import { readFileSync } from "node:fs";
  8. import yargs from "yargs";
  9. import { hideBin } from "yargs/helpers";
  10. import { COMMON_DEPLOY_OPTIONS } from "./common";
  11. import { toPrivateKey } from "../src/core/base";
  12. import { EvmChain } from "../src/core/chains";
  13. import { DefaultStore } from "../src/node/utils/store";
  14. const parser = yargs(hideBin(process.argv))
  15. .scriptName("deploy_evm_contract.ts")
  16. .usage(
  17. "Usage: $0 --std-output <path/to/std-output.json> --private-key <private-key> --chain <chain> [--deploy-args <arg> [... <args>]]",
  18. )
  19. .options({
  20. "std-output": {
  21. type: "string",
  22. demandOption: true,
  23. desc: "Path to the standard JSON output of the contract (build artifact)",
  24. },
  25. "private-key": COMMON_DEPLOY_OPTIONS["private-key"],
  26. chain: {
  27. type: "string",
  28. demandOption: true,
  29. desc: "Chain to upload the contract on. Must be one of the chains available in the store",
  30. },
  31. "deploy-args": {
  32. type: "array",
  33. desc: "Arguments to pass to the contract constructor. They should not be prefixed with 0x.",
  34. },
  35. });
  36. async function main() {
  37. const argv = await parser.argv;
  38. const chain = DefaultStore.getChainOrThrow(argv.chain, 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.object, // As per the artifacts generated by forge, bytecode is an object with an 'object' property
  44. argv["deploy-args"] ?? [],
  45. );
  46. console.log(`Deployed contract at ${address}`);
  47. }
  48. main();