Skip to main content

TRC20ContractBalance gRPC Method

Loading...

Updated on
May 13, 2025

TRC20ContractBalance gRPC Method

Parameters

addr
string
REQUIRED
Loading...
contractAddress
string
REQUIRED
Loading...

Returns

balance
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
accountAddress := "TPyjyZfsYaXStgz2NmAraF1uZcMtkgNan5"
50
contractAddress := "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"
51
52
balance, err := conn.TRC20ContractBalance(accountAddress, contractAddress)
53
if err != nil {
54
fmt.Printf("Error calling TRC20ContractBalance: %v\n", err)
55
return
56
}
57
58
jsonData, _ := json.MarshalIndent(balance, "", " ")
59
fmt.Println(string(jsonData))
60
61
}
Don't have an account yet?
Create your Quicknode endpoint in seconds and start building
Get started for free