-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbalance.go
43 lines (36 loc) · 886 Bytes
/
balance.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package tronscansdk
import (
"context"
"encoding/json"
"errors"
"fmt"
httpClientGoLib "github.com/trustwallet/go-libs/client"
"net/url"
)
func GetBalanceOfUsdt(ctx context.Context, addressWallet string) (string, error) {
path := fmt.Sprintf("%s", AccountTokenList)
req := httpClientGoLib.InitClient(BaseUrl, nil)
nb := httpClientGoLib.NewReqBuilder()
nb.Query(url.Values{
"address": []string{addressWallet},
})
nb.Method("GET").PathStatic(path)
body, err := req.Execute(ctx, nb.Build())
if err != nil {
return "", err
}
b := TronBalanceOfAccount{}
err = json.Unmarshal(body, &b)
if err != nil {
return "", err
}
if b.Data == nil {
return "", errors.New("failed to parse response of request")
}
for _, tokenList := range b.Data {
if tokenList.TokenId == ContractAddressUsdt {
return fmt.Sprint(tokenList.Quantity), nil
}
}
return "0", nil
}