GetRewardsInfo gRPC Method
Parameters
address
string
REQUIRED
The TRON account address to check rewards for
Returns
rewardsInfo
integer
Total amount of unclaimed rewards in SUN (1 TRX = 1,000,000 SUN)
Request
package main import ( "context" "crypto/tls" "fmt" "github.com/fbsobreira/gotron-sdk/pkg/client" "google.golang.org/grpc" "google.golang.org/grpc/credentials" "log" ) // 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() addr := "TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g" fmt.Printf("Fetching rewards info for address: %s\n", addr) rewardsInfo, err := conn.GetRewardsInfo(addr) if err != nil { log.Fatalf("Error getting rewards info: %v\n", err) } fmt.Println("\nRewards Information:") rewards := rewardsInfo // Convert from SUN to TRX for better readability (1 TRX = 1,000,000 SUN) rewardsTRX := float64(rewards) / 1000000.0 fmt.Printf("Total Rewards: %d SUN (%.6f TRX)\n", rewards, rewardsTRX) if rewards > 0 { fmt.Println("\nThese rewards are accumulated from:") fmt.Println("- Block production (for Super Representatives)") fmt.Println("- Voting for Super Representatives") fmt.Println("- Other network incentives") fmt.Println("\nRewards can be withdrawn using the withdrawal function.") } else { fmt.Println("\nNo rewards available for this address.") fmt.Println("Rewards can be earned by:") fmt.Println("- Voting for Super Representatives") fmt.Println("- Becoming a Super Representative") } }
Don't have an account yet?
Create your QuickNode endpoint in seconds and start building
Get started for free