blocto / solana-go-sdk

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

Querying a wallets transactions #75

Closed scottywm closed 2 years ago

scottywm commented 2 years ago

Hey, a few days ago I asked how I can use your library to query the transactions for a given wallet and I didn't understand your answer.

I need to retrieve transactions for a wallet and paginate through them.

Can I use your library to do this and if so how?

yihau commented 2 years ago

https://portto.github.io/solana-go-sdk/rpc/get-signatures-for-address.html

scottywm commented 2 years ago

Hey, thanks for the link above, its working good for me.

I'm using the wallet address to get the transaction signatures and then I use the transaction signatures to get the transactions, only the signatures property in the transactions is an array and it looks like the signature is encoded.

I use this line of code to get the transactions

tr, errTran := c.GetTransaction(context.Background(), signature)

How do I get the signature from this encoded signature value?

Thanks

Joeyboy92 commented 2 years ago

Hey, I'm having the same problem too. It looks like the actual transaction signature that is in the transactions filed is encoded somehow. I can't decode it either.

yihau commented 2 years ago

signatures on explorer are base58 encoded strings. lots of RPC do use them as well. if you do base58 decode, you will get a 64 bytes array. they are the same value, just represent by different text-encoded. In the other words, when you get a signature that is a byte array. you can just base58 encode it to get a human-friendly string.

scottywm commented 2 years ago

Hey, when i use your library to get the transaction, I'm needing to find the senders address and the recipients address and I have been relying on the order in which the sender and receiver details are inside the field PostTokenBalances, as shown below.

tr, _ := c.GetTransaction(context.Background(), sig)

recipient := tr.Meta.PostTokenBalances[1].Owner sender := tr.Meta.PostTokenBalances[0].Owner

The problem I'm having is that sometimes the order in both of the PostTokenBalances and PreTokenBalances fields seems to change around and cause errors in my application.

Are you aware of this problem and how can I work around this to get the correct recipient and sender addresses?

yihau commented 2 years ago

pre/post balance and pre/post token balance can only know the final result. if a tx is like A send B 100 token, B send C 100 token, you can only know A lost 100 and C get 100 but you don't have any idea B is the man in the middle. if you would like to know the detail, you need to parse instructions. for decoding an instruction, every program can define on their own way. you should take a look to the program

scottywm commented 2 years ago

Thanks 🙏🙏🙏🙏