transfer_tokens.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /// We build a programmable txn to create a price feed.
  2. import dotenv from "dotenv";
  3. import {
  4. RawSigner,
  5. SUI_CLOCK_OBJECT_ID,
  6. TransactionBlock,
  7. JsonRpcProvider,
  8. Ed25519Keypair,
  9. Connection,
  10. } from "@optke3/sui.js";
  11. dotenv.config({ path: "~/.env" });
  12. import { REGISTRY, NETWORK } from "../registry";
  13. // Network dependent settings.
  14. let network = NETWORK.TESTNET; // <= NOTE: Update this when changing network
  15. const walletPrivateKey = process.env.SUI_TESTNET; // <= NOTE: Update this when changing network
  16. const registry = REGISTRY[network];
  17. const provider = new JsonRpcProvider(
  18. new Connection({ fullnode: registry["RPC_URL"] })
  19. );
  20. async function main() {
  21. if (walletPrivateKey === undefined) {
  22. throw new Error("SUI_TESTNET unset in environment");
  23. }
  24. const wallet = new RawSigner(
  25. Ed25519Keypair.fromSecretKey(Buffer.from(walletPrivateKey, "hex")),
  26. provider
  27. );
  28. let sender = await wallet.getAddress();
  29. let recipient =
  30. "0x893a6889c5252ce9945148675ab414a90f820ca91d927f14fb7cd781bc09512a";
  31. console.log("Sender: ", sender);
  32. transfer_tokens(wallet, recipient);
  33. }
  34. main();
  35. async function transfer_tokens(signer: RawSigner, recipient: string) {
  36. const tx = new TransactionBlock();
  37. let coin = tx.splitCoins(tx.gas, [tx.pure(971000000)]);
  38. tx.transferObjects([coin], tx.pure(recipient));
  39. tx.setGasBudget(1000000000);
  40. let result = await signer.signAndExecuteTransactionBlock({
  41. transactionBlock: tx,
  42. options: {
  43. showInput: true,
  44. showEffects: true,
  45. showEvents: true,
  46. showObjectChanges: true,
  47. showBalanceChanges: true,
  48. },
  49. });
  50. console.log(result);
  51. return result;
  52. }