0x0x230x

Untitled

Jan 21st, 2025
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. const senderTokenAccount = await this.getTokenAccount(
  2. params.senderAddress,
  3. params.tokenMint,
  4. );
  5.  
  6. if (!senderTokenAccount) {
  7. throw new Error('Sender token account not found');
  8. }
  9.  
  10. const { tokenAccount: recipientTokenAccount, shouldCreate } =
  11. await this.getOrCreateTokenAccount(
  12. params.recipientAddress,
  13. params.tokenMint,
  14. );
  15.  
  16. if (shouldCreate) {
  17. instructions.push(
  18. createAssociatedTokenAccountInstruction(
  19. new PublicKey(params.senderAddress),
  20. recipientTokenAccount,
  21. new PublicKey(params.recipientAddress),
  22. new PublicKey(params.tokenMint),
  23. ),
  24. );
  25. }
  26.  
  27. instructions.push(
  28. createTransferInstruction(
  29. senderTokenAccount,
  30. recipientTokenAccount,
  31. new PublicKey(params.senderAddress),
  32. params.amount,
  33. ),
  34. );
  35.  
  36. const { blockhash } = await this.connection.getLatestBlockhash({
  37. commitment: 'recent',
  38. });
  39.  
  40. const messageV0 = new TransactionMessage({
  41. payerKey: new PublicKey(params.senderAddress),
  42. recentBlockhash: blockhash,
  43. instructions,
  44. }).compileToV0Message();
  45.  
  46. return new VersionedTransaction(messageV0);
Advertisement
Add Comment
Please, Sign In to add comment