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()
fmt.Println("Fetching complete list of TRC10 tokens...")
page := int64(-1) // Use -1 to get all tokens
assetList, err := conn.GetAssetIssueList(page)
if err != nil {
log.Fatalf("Error getting asset issue list: %v", err)
}
totalTokens := len(assetList.AssetIssue)
fmt.Printf("\nTotal TRC10 tokens found: %d\n", totalTokens)
// Display the first few tokens as an example
fmt.Println("\nSample of first 5 tokens:")
displayCount := 5
if totalTokens < displayCount {
displayCount = totalTokens
}
for i := 0; i < displayCount; i++ {
token := assetList.AssetIssue[i]
fmt.Printf("\n%d. ID: %s\n", i+1, token.Id)
fmt.Printf(" Name: %s\n", string(token.Name))
fmt.Printf(" Symbol: %s\n", string(token.Abbr))
fmt.Printf(" Decimals: %d\n", token.Precision)
fmt.Printf(" Total Supply: %d\n", token.TotalSupply)
}
}