0

My typescripts program swaps tokens but creates an account token each time. I saw on Solscan that it is possible not to create an account. how can I do it, any advice or code? sample transaction: https://solscan.io/tx/268kSVoy8rf2qTuysWPSPkjiNHAH8ZLmV1e1Jk8N7JaYx9VUMDDXd678AZFeUiReKbiZyUqL9yTKeSzPS17BPARA

1 Answer 1

2

All tokens, other than NATIVE_TOKEN (unwrapped Solana), (and perhaps Compressed NFTs), require an Associated Token Account.

The transaction you linked does indeed create and use an Associated Token Account: EnJ5PjCYLag51YcoBFwAUN9RSoiftduCxR7hCtT3Z6v3.

If the token account already exists for the receiver in question, you can use it. This function is helpful:

getOrCreateAssociatedTokenAccount(connection, payer, mint, owner, allowOwnerOffCurve?, commitment?, confirmOptions?, programId?, associatedTokenProgramId?): Promise<Account>

Link to Function Reference

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.