ParseTRC20NumericProperty gRPC Method
Parameters
data
string
REQUIRED
Loading...
Returns
value
string
Loading...
error
object
Loading...
Request
package main import ( "context" "crypto/tls" "fmt" "encoding/hex" "github.com/fbsobreira/gotron-sdk/pkg/client" "google.golang.org/grpc" "google.golang.org/grpc/credentials" ) // QuickNode endpoints consist of two crucial components: the endpoint name and the corresponding token // For eg: QN Endpoint: https://docs-demo.tron-mainnet.quiknode.pro/abcde123456789 // endpoint will be: docs-demo.tron-mainnet.quiknode.pro:50051 {50051 is the port number for Tron gRPC} // token will be : abcde123456789 var token = "YOUR_TOKEN" var endpoint = "YOUR_ENDPOINT:50051" type auth struct { token string } func (a *auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) { return map[string]string{ "x-token": a.token, }, nil } func (a *auth) RequireTransportSecurity() bool { return false } func main() { opts := []grpc.DialOption{ grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})), grpc.WithPerRPCCredentials(&auth{token}), } conn := client.NewGrpcClient(endpoint) if err := conn.Start(opts...); err != nil { panic(err) } defer conn.Conn.Close() ownerAddress := "THPvaUhoh2Qn2y9THCZML3H815hhFhn5YC" contractAddress := "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t" method := "totalSupply()" jsonParams := "" response, err := conn.TriggerConstantContract( ownerAddress, contractAddress, method, jsonParams, ) if err != nil { fmt.Printf("Error calling TriggerConstantContract: %v\n", err) return } if len(response.ConstantResult) == 0 { fmt.Println("No result returned from contract call") return } hexData := hex.EncodeToString(response.ConstantResult[0]) numericValue, err := conn.ParseTRC20NumericProperty(hexData) if err != nil { fmt.Printf("Error parsing numeric property: %v\n", err) return } fmt.Printf("Parsed numeric value: %s\n", numericValue.String()) }
Don't have an account yet?
Create your QuickNode endpoint in seconds and start building
Get started for free