initialize_testnet.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { createInitializeInstruction } from "@certusone/wormhole-sdk/lib/cjs/solana/wormhole";
  2. import { AnchorProvider, Wallet, web3 } from "@coral-xyz/anchor";
  3. import { bs58 } from "@coral-xyz/anchor/dist/cjs/utils/bytes";
  4. // Usage:
  5. // RPC_URL="https://api.devnet.solana.com" CORE_BRIDGE_PROGRAM_ID=3u8hJUVTA4jH1wYAyUur7FFZVQ8H635K3tSHHF4ssjQ5 SOLANA_KEY="<full_path>.json" npx tsx post_message.ts
  6. (async () => {
  7. const RPC_URL = process.env.RPC_URL;
  8. if (!RPC_URL) {
  9. throw new Error("RPC_URL is required");
  10. }
  11. const CORE_BRIDGE_PROGRAM_ID = process.env.CORE_BRIDGE_PROGRAM_ID;
  12. if (!CORE_BRIDGE_PROGRAM_ID) {
  13. throw new Error("CORE_BRIDGE_PROGRAM_ID is required");
  14. }
  15. const coreBridgeAddress = new web3.PublicKey(CORE_BRIDGE_PROGRAM_ID);
  16. const connection = new web3.Connection(RPC_URL, "confirmed");
  17. const key = process.env.SOLANA_KEY;
  18. if (!key) {
  19. throw new Error("SOLANA_KEY is required");
  20. }
  21. const payer = web3.Keypair.fromSecretKey(
  22. key.endsWith(".json") ? new Uint8Array(require(key)) : bs58.decode(key)
  23. );
  24. const provider = new AnchorProvider(connection, new Wallet(payer));
  25. const ix = createInitializeInstruction(
  26. coreBridgeAddress,
  27. payer.publicKey.toString(),
  28. 86400,
  29. BigInt(100),
  30. [Buffer.from("13947Bd48b18E53fdAeEe77F3473391aC727C638", "hex")]
  31. );
  32. const transaction = new web3.Transaction();
  33. transaction.add(ix);
  34. const tx = await provider.sendAndConfirm(transaction);
  35. console.log(tx);
  36. })();