Skip to main content

TRC20GetDecimals gRPC Method

Loading...

Updated on
May 13, 2025

TRC20GetDecimals gRPC Method

Parameters

contractAddress
string
REQUIRED
Loading...

Returns

decimals
string
Loading...
error
object
Loading...
Request
1
package main
2
3
import (
4
"context"
5
"crypto/tls"
6
"fmt"
7
"encoding/json"
8
9
"github.com/fbsobreira/gotron-sdk/pkg/client"
10
"google.golang.org/grpc"
11
"google.golang.org/grpc/credentials"
12
)
13
14
15
// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token
16
// For eg: QN Endpoint: https://docs-demo.tron-mainnet.quiknode.pro/abcde123456789
17
// endpoint will be: docs-demo.tron-mainnet.quiknode.pro:50051 {50051 is the port number for Tron gRPC}
18
// token will be : abcde123456789
19
20
var token = "YOUR_TOKEN"
21
var endpoint = "YOUR_ENDPOINT:50051"
22
23
24
type auth struct {
25
token string
26
}
27
28
func (a *auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
29
return map[string]string{
30
"x-token": a.token,
31
}, nil
32
}
33
34
func (a *auth) RequireTransportSecurity() bool {
35
return false
36
}
37
38
func main() {
39
opts := []grpc.DialOption{
40
grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),
41
grpc.WithPerRPCCredentials(&auth{token}),
42
}
43
conn := client.NewGrpcClient(endpoint)
44
if err := conn.Start(opts...); err != nil {
45
panic(err)
46
}
47
defer conn.Conn.Close()
48
49
contractAddress := "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"
50
51
decimals, err := conn.TRC20GetDecimals(contractAddress)
52
if err != nil {
53
fmt.Printf("Error calling TRC20GetDecimals: %v\n", err)
54
return
55
}
56
57
jsonData, _ := json.MarshalIndent(decimals, "", " ")
58
fmt.Println(string(jsonData))
59
60
}
Don't have an account yet?
Create your Quicknode endpoint in seconds and start building
Get started for free