deploy_evm_contract.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import yargs from "yargs";
  2. import { hideBin } from "yargs/helpers";
  3. import { EvmChain } from "../src/core/chains";
  4. import { DefaultStore } from "../src/node/utils/store";
  5. import { readFileSync } from "fs";
  6. import { toPrivateKey } from "../src/core/base";
  7. import { COMMON_DEPLOY_OPTIONS } from "./common";
  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();