Skip to main content

ParseTRC20NumericProperty gRPC Method

Loading...

Updated on
May 13, 2025

ParseTRC20NumericProperty gRPC Method

Parameters

data
string
REQUIRED
Loading...

Returns

value
string
Loading...
error
object
Loading...
Request
1
package main
2
3
import (
4
"context"
5
"crypto/tls"
6
"fmt"
7
"encoding/hex"
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
ownerAddress := "THPvaUhoh2Qn2y9THCZML3H815hhFhn5YC"
50
contractAddress := "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"
51
method := "totalSupply()"
52
jsonParams := ""
53
54
response, err := conn.TriggerConstantContract(
55
ownerAddress,
56
contractAddress,
57
method,
58
jsonParams,
59
)
60
if err != nil {
61
fmt.Printf("Error calling TriggerConstantContract: %v\n", err)
62
return
63
}
64
65
if len(response.ConstantResult) == 0 {
66
fmt.Println("No result returned from contract call")
67
return
68
}
69
70
hexData := hex.EncodeToString(response.ConstantResult[0])
71
72
numericValue, err := conn.ParseTRC20NumericProperty(hexData)
73
if err != nil {
74
fmt.Printf("Error parsing numeric property: %v\n", err)
75
return
76
}
77
78
fmt.Printf("Parsed numeric value: %s\n", numericValue.String())
79
80
}
Don't have an account yet?
Create your Quicknode endpoint in seconds and start building
Get started for free