blocto / solana-go-sdk

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

Best Way to Unmarshal Data Field in Response? #40

Closed koalateectrl closed 2 years ago

koalateectrl commented 2 years ago

When I call a method, for example GetAccountInfo and I receive a response, the response unmarshals fields such as lamports, owner, executable etc in human-readable form, but the Data field comes in a byte array.

What is the best/easiest way for me to convert this byte array into a human readable form (such as JSON), specifically if I don't know the specific fields that will be returned?

yihau commented 2 years ago

For decoding account data, you will need to know how program serialized it. You can take a look at how I do in decoding token account. or you can use raw rpc client and give jsonParsed as the encoding. It will decode some build-in account data for you (like token account, vote account ...)