gagliardetto / solana-go

Go SDK library and RPC client for the Solana Blockchain
Apache License 2.0
930 stars 264 forks source link

UiTokenAmount data type #191

Closed lucasoares closed 7 months ago

lucasoares commented 7 months ago

What is the reason the UiAmount *float64 is deprecated? I saw the blame information and apparently, the UiAmount was previously of the type *bin.JSONFloat64.

I don't know which field is reliable and when I should use each one of them... And if I use the string type, should I use a type from bin library to parse it?

0xvbetsun commented 7 months ago

let's refer to the documentation of solana RPC.

I'd recommend parsing amount and using decimals for your internal calculations

to achieve this bin is not mandatory. Just use stdlib

// to uint64
amnt, err := strconv.ParseUint(amount, 10, 64)

// or to *big.Int
amnt, ok := new(big.Int).SetString(amount, 10)