22import { createClient , generateKeyPairSigner , lamports } from "@solana/kit" ;
33import { solanaLocalRpc } from "@solana/kit-plugin-rpc" ;
44import { payer } from "@solana/kit-plugin-signer" ;
5- import {
6- fetchToken ,
7- findAssociatedTokenPda ,
8- TOKEN_PROGRAM_ADDRESS ,
9- tokenProgram ,
10- } from "@solana-program/token" ;
5+ import { tokenProgram } from "@solana-program/token" ;
116
127// Generate keypairs for fee payer, sender, recipient, and mint
138const feePayer = await generateKeyPairSigner ( ) ;
@@ -48,27 +43,9 @@ const setup = await client.sendTransaction([createMintIx, mintToSenderIx]);
4843console . log ( "Transaction Signature:" , setup . context . signature ) ;
4944console . log ( "Successfully minted 1.0 tokens" ) ;
5045
51- // Derive the ATAs for fee payer, sender and recipient
52- const [ senderAta ] = await findAssociatedTokenPda ( {
53- mint : mint . address ,
54- owner : sender . address ,
55- tokenProgram : TOKEN_PROGRAM_ADDRESS ,
56- } ) ;
57- const [ recipientAta ] = await findAssociatedTokenPda ( {
58- mint : mint . address ,
59- owner : recipient . address ,
60- tokenProgram : TOKEN_PROGRAM_ADDRESS ,
61- } ) ;
62- const [ feePayerAta ] = await findAssociatedTokenPda ( {
63- mint : mint . address ,
64- owner : feePayer . address ,
65- tokenProgram : TOKEN_PROGRAM_ADDRESS ,
66- } ) ;
67-
6846// Transfer tokens to recipient
6947const transferToRecipientIx = await client . token . instructions . transferToATA ( {
7048 mint : mint . address ,
71- source : senderAta ,
7249 authority : sender ,
7350 recipient : recipient . address ,
7451 amount : 50n ,
@@ -79,7 +56,6 @@ const transferToRecipientIx = await client.token.instructions.transferToATA({
7956// For a real-world application, calculate this from the SOL fee.
8057const reimburseFeePayerIx = await client . token . instructions . transferToATA ( {
8158 mint : mint . address ,
82- source : senderAta ,
8359 authority : sender ,
8460 recipient : feePayer . address ,
8561 amount : 50n ,
@@ -95,23 +71,4 @@ console.log(
9571 "Successfully transferred 0.5 tokens to recipient + 0.5 to fee payer" ,
9672) ;
9773
98- // Final balances
99- const [ feePayerAcct , senderAcct , recipientAcct ] = await Promise . all ( [
100- fetchToken ( client . rpc , feePayerAta , { commitment : "confirmed" } ) ,
101- fetchToken ( client . rpc , senderAta , { commitment : "confirmed" } ) ,
102- fetchToken ( client . rpc , recipientAta , { commitment : "confirmed" } ) ,
103- ] ) ;
104-
105- console . log ( "=== Final Balances ===" ) ;
106- console . log (
107- "Fee Payer balance:" ,
108- Number ( feePayerAcct . data . amount ) / 100 ,
109- "tokens" ,
110- ) ;
111- console . log ( "Sender balance:" , Number ( senderAcct . data . amount ) / 100 , "tokens" ) ;
112- console . log (
113- "Recipient balance:" ,
114- Number ( recipientAcct . data . amount ) / 100 ,
115- "tokens" ,
116- ) ;
11774// #endregion pay-fees
0 commit comments