migrate_testnet.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { LCDClient, MnemonicKey } from "@terra-money/terra.js";
  2. import {
  3. MsgMigrateContract,
  4. } from "@terra-money/terra.js";
  5. import axios from "axios";
  6. import yargs from "yargs";
  7. import { hideBin } from "yargs/helpers";
  8. export const TERRA_GAS_PRICES_URL = "https://fcd.terra.dev/v1/txs/gas_prices";
  9. const argv = yargs(hideBin(process.argv))
  10. .option('code_id', {
  11. description: 'Which code id to upgrade to',
  12. type: 'number',
  13. })
  14. .option('mnemonic', {
  15. description: 'Mnemonic (private key)',
  16. type: 'string',
  17. required: true
  18. })
  19. .option('contract', {
  20. description: 'Contract to upgrade',
  21. type: 'string',
  22. required: true
  23. })
  24. .help()
  25. .alias('help', 'h').argv;
  26. /* Set up terra client & wallet */
  27. const terra_host = {
  28. URL: "https://bombay-lcd.terra.dev",
  29. chainID: "bombay-12",
  30. name: "testnet",
  31. };
  32. const lcd = new LCDClient(terra_host);
  33. const feeDenoms = ["uluna"];
  34. const gasPrices = await axios
  35. .get(TERRA_GAS_PRICES_URL)
  36. .then((result) => result.data);
  37. const wallet = lcd.wallet(
  38. new MnemonicKey({
  39. mnemonic: argv.mnemonic
  40. })
  41. );
  42. await wallet.sequence();
  43. /* Do upgrade */
  44. const tx = await wallet.createAndSignTx({
  45. msgs: [
  46. new MsgMigrateContract(
  47. wallet.key.accAddress,
  48. argv.contract,
  49. argv.code_id,
  50. {
  51. "action": ""
  52. },
  53. { uluna: 1000 }
  54. ),
  55. ],
  56. memo: "",
  57. feeDenoms,
  58. gasPrices,
  59. });
  60. const rs = await lcd.tx.broadcast(tx);
  61. console.log(rs);