Skip to main content

GetRewardsInfo gRPC Method

Loading...

Updated on
May 13, 2025

GetRewardsInfo gRPC Method

Parameters

address
string
REQUIRED
Loading...

Returns

rewardsInfo
integer
Loading...
Request
1
package main
2
3
import (
4
"context"
5
"crypto/tls"
6
"fmt"
7
"github.com/fbsobreira/gotron-sdk/pkg/client"
8
"google.golang.org/grpc"
9
"google.golang.org/grpc/credentials"
10
"log"
11
)
12
13
// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token
14
// For eg: QN Endpoint: https://docs-demo.tron-mainnet.quiknode.pro/abcde123456789
15
// endpoint will be: docs-demo.tron-mainnet.quiknode.pro:50051 {50051 is the port number for Tron gRPC}
16
// token will be : abcde123456789
17
18
var token = "YOUR_TOKEN"
19
var endpoint = "YOUR_ENDPOINT:50051"
20
21
type auth struct {
22
token string
23
}
24
25
func (a *auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
26
return map[string]string{
27
"x-token": a.token,
28
}, nil
29
}
30
31
func (a *auth) RequireTransportSecurity() bool {
32
return false
33
}
34
35
func main() {
36
37
opts := []grpc.DialOption{
38
grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),
39
grpc.WithPerRPCCredentials(&auth{token}),
40
}
41
conn := client.NewGrpcClient(endpoint)
42
if err := conn.Start(opts...); err != nil {
43
panic(err)
44
}
45
defer conn.Conn.Close()
46
47
addr := "TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g"
48
fmt.Printf("Fetching rewards info for address: %s\n", addr)
49
rewardsInfo, err := conn.GetRewardsInfo(addr)
50
if err != nil {
51
log.Fatalf("Error getting rewards info: %v\n", err)
52
}
53
54
fmt.Println("\nRewards Information:")
55
rewards := rewardsInfo
56
// Convert from SUN to TRX for better readability (1 TRX = 1,000,000 SUN)
57
rewardsTRX := float64(rewards) / 1000000.0
58
fmt.Printf("Total Rewards: %d SUN (%.6f TRX)\n", rewards, rewardsTRX)
59
60
if rewards > 0 {
61
fmt.Println("\nThese rewards are accumulated from:")
62
fmt.Println("- Block production (for Super Representatives)")
63
fmt.Println("- Voting for Super Representatives")
64
fmt.Println("- Other network incentives")
65
fmt.Println("\nRewards can be withdrawn using the withdrawal function.")
66
} else {
67
fmt.Println("\nNo rewards available for this address.")
68
fmt.Println("Rewards can be earned by:")
69
fmt.Println("- Voting for Super Representatives")
70
fmt.Println("- Becoming a Super Representative")
71
}
72
}
Don't have an account yet?
Create your Quicknode endpoint in seconds and start building
Get started for free