1

I am using https://github.com/ajamaica/Solana.kt this library for Solana SPL token transfer. I can successfully create a Token Account address using this library by using https://github.com/ajamaica/Solana.kt/blob/master/rxSolana/src/main/java/com/solana/rxsolana/actions/createTokenAccount.kt this class. But i can create is only for Sender.

If i am sender then i have my secret key and i can create my token account address if there's not already created. Now i want to send my spl token to user2 but that user have no token account address created before. So before sending spl token i want to create token account address for user2. Can anyone help? How can i do that?

Hemangi
  • 11
  • 1
  • how did you import this library? Can you write an answer to my [question](https://stackoverflow.com/questions/75367084/how-to-add-solanakt-to-my-project-kotlin)? – Leo Loki Feb 08 '23 at 20:44

1 Answers1

1

Typically, if you want to send an spl-token to a user, you will send it to their "associated token account" for that token.

In your case, you need to create the associated token account for "user2" before sending the token to them. It looks like there's some support for associated token accounts in this package, using createAssociatedTokenAccountInstruction

https://github.com/ajamaica/Solana.kt/blob/1a79932e67e698f2dba5f347fb74dd47d702f8fb/solana/src/main/java/com/solana/programs/AssociatedTokenProgram.kt

In fact, it looks like this case is already covered, since sendSPLTokens will automatically do this check and create the account if needed! https://github.com/ajamaica/Solana.kt/blob/1a79932e67e698f2dba5f347fb74dd47d702f8fb/solana/src/main/java/com/solana/actions/sendSPLTokens.kt#L13

Jon C
  • 7,019
  • 10
  • 17
  • @Jon C, would you know how this would look like using solana web3 native library. I would like to create a transaction without a Signer and then add it to the transaction array using https://docs.phantom.app/integrating/extension-and-in-app-browser-web-apps/sending-a-transaction#signing-multiple-transactions – Digital Dom Jul 07 '22 at 14:27
  • @DigitalDom that sounds like a bit of a different question, would you mind asking it separately? – Jon C Jul 07 '22 at 17:45
  • Is does @Jon C and for anyone who is still struggling with it here are good resources for preparing a transaction object and then signing it with phantom wallet: https://stackoverflow.com/questions/71721805/debugging-transaction-simulation-failed-when-sending-program-instruction-sola https://stackoverflow.com/questions/68236211/how-to-transfer-custom-token-by-solana-web3-js And these infos should be more readily and easily available on the official docs of Phantom, Solana. The docs are really shi..tty for new devs in the ecosystem. – Digital Dom Jul 08 '22 at 11:11
  • Great, thanks! And yeah, docs are a constant moving target... It's all open source, so contributions are always appreciated! The Solana Cookbook is a great place for examples https://solanacookbook.com/#contributing, and otherwise the official docs are at https://github.com/solana-labs/solana/tree/master/docs – Jon C Jul 08 '22 at 17:51