blocto / solana-go-sdk

Solana Golang SDK
https://blocto.github.io/solana-go-sdk/
MIT License
366 stars 95 forks source link

How to transfer token? #91

Closed femtoeu closed 1 year ago

femtoeu commented 1 year ago

Hello, i'm want to tranfer token. I created account where i have token which i want to transfer. I have tokenAddress and tokenAccount of token which i want to transfer.

I also read the page https://yihau.gitbook.io/solana-go/tour/transfer-1 , but I don't understand what From, To, Mint is. To get these values, do I need to create an account before sending? Is it possible to find an example of sending a token somewhere?

yihau commented 1 year ago

https://portto.github.io/solana-go-sdk/tour/token-transfer.html

Give you some point:

  1. you can treat mint as ERC20 token. In Solana, USDC, RAY, SRM... all of them are mints and they have different address.
  2. a token account can only hold a kind of token. if you have a USDC token account, if you would like to receive RAY, you need to create another RAY token account.
  3. token transfer's from and to are both token account.
  4. I recommend you follow the example from create mint. it tells you how to create your own token and create a token account belong to it. if you have already have a token account, you can use https://portto.github.io/solana-go-sdk/tour/get-token-account.html to know what kind of token it can receive.
  5. you can use https://github.com/portto/solana-go-sdk/blob/main/docs/_examples/client/get-token-accounts-by-owner/main.go to get all token accounts which owned by an owner.
  6. if your receiver don't have a token account, you need to create one so that you can finish your token trasnferring.
yihau commented 1 year ago

feel free to reopen this if you would like to discuss further

femtoeu commented 1 year ago

Hello. Thanks to your help I understand everything except "if your receiver don't have a token account, you need to create one so that you can finish your token trasnferring. Can I do this without having a Private Key from his account?