transfer_tokens.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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(
  26. Buffer.from(walletPrivateKey, "hex")
  27. ),
  28. provider
  29. );
  30. let sender = await wallet.getAddress()
  31. let recipient = "0x4ed01b6abcc271a5c7a1e05ee9344d6eb72d0c1f2483a1c600b46d73a22ba764"
  32. console.log("Sender: ", sender);
  33. transfer_tokens(wallet, recipient);
  34. }
  35. main();
  36. async function transfer_tokens(
  37. signer: RawSigner,
  38. recipient: string
  39. ) {
  40. const tx = new TransactionBlock();
  41. let coin = tx.splitCoins(tx.gas, [tx.pure(100000000000)]);
  42. tx.transferObjects([coin], tx.pure(recipient))
  43. tx.setGasBudget(1000000000);
  44. let result = await signer.signAndExecuteTransactionBlock({
  45. transactionBlock: tx,
  46. options: {
  47. showInput: true,
  48. showEffects: true,
  49. showEvents: true,
  50. showObjectChanges: true,
  51. showBalanceChanges: true,
  52. },
  53. });
  54. console.log(result);
  55. return result;
  56. }