blocto / solana-go-sdk

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

Get the token account by the owner address #79

Closed scottywm closed 2 years ago

scottywm commented 2 years ago

Hello I'm trying to use the function "GetTokenAccountsByOwner" using the rpc variable and I keep getting an error in my response as its telling me that the the way I'm encoding my data is wrong.

I am encoding the "solanaWallet" variable to base58 as it says in the library and inside the "conf" variable I'm not encoding it at all because it doesnt say to.

Below is my code

rpcClient := rpc.NewRpcClient(rpc.MainnetRPCEndpoint)

var mintPubkey = os.Getenv("MINT_ADDRRESS")

var solWallet = common.PublicKeyFromString("EbqSErUSAFdf9pCE2WtBnM1ZNgLi2zUraS463XSBpc59")
solanaWallet := solWallet.ToBase58()

conf := rpc.GetTokenAccountsByOwnerConfigFilter{}
conf.Mint = mintPubkey

result, _ := rpcClient.GetTokenAccountsByOwner(context.Background(), solanaWallet, conf)

the result gives me an error with the message; "Encoded binary (base 58) data should be less than 128 bytes, please use Base64 encoding." And the error code is, -32600

When I use base64 to encode the address, the error message reads; "Invalid param: WrongSize" And the error code is, -32602

As far as I can tell I'm doing everything the library is telling me to do and I keep getting errors, please tell me what I'm doing wrong.

Thanks

Scott

yihau commented 2 years ago

I added a new function, you may take a look at https://github.com/portto/solana-go-sdk/blob/main/docs/_examples/client/get-token-accounts-by-owner/main.go