deploy_evm_contract.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { readFileSync } from "node:fs";
  2. import yargs from "yargs";
  3. import { hideBin } from "yargs/helpers";
  4. import { COMMON_DEPLOY_OPTIONS } from "./common";
  5. import { toPrivateKey } from "../src/core/base";
  6. import { EvmChain } from "../src/core/chains";
  7. import { DefaultStore } from "../src/node/utils/store";
  8. const parser = yargs(hideBin(process.argv))
  9. .scriptName("deploy_evm_contract.ts")
  10. .usage(
  11. "Usage: $0 --std-output <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 JSON output of the contract (build artifact)",
  18. },
  19. "private-key": COMMON_DEPLOY_OPTIONS["private-key"],
  20. chain: {
  21. type: "string",
  22. demandOption: true,
  23. desc: "Chain to upload the contract on. Must be one of the chains available in the store",
  24. },
  25. "deploy-args": {
  26. type: "array",
  27. desc: "Arguments to pass to the contract constructor. They should not be prefixed with 0x.",
  28. },
  29. });
  30. async function main() {
  31. const argv = await parser.argv;
  32. const chain = DefaultStore.getChainOrThrow(argv.chain, EvmChain);
  33. const artifact = JSON.parse(readFileSync(argv["std-output"], "utf8"));
  34. const address = await chain.deploy(
  35. toPrivateKey(argv["private-key"]),
  36. artifact.abi,
  37. artifact.bytecode.object, // As per the artifacts generated by forge, bytecode is an object with an 'object' property
  38. argv["deploy-args"] || [],
  39. );
  40. console.log(`Deployed contract at ${address}`);
  41. }
  42. main();