Skip to main content

ListNodes gRPC Method

Loading...

Updated on
May 13, 2025

ListNodes gRPC Method

Parameters

This method does not accept any parameters

Returns

nodes
array
Loading...
address
object
Loading...
host
string
Loading...
port
integer
Loading...
error
object
Loading...
Request
1
package main
2
3
import (
4
"context"
5
"crypto/tls"
6
"encoding/json"
7
"fmt"
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
48
fmt.Println("Listing network nodes:")
49
nodes, err := conn.ListNodes()
50
if err != nil {
51
fmt.Printf("Error listing nodes: %v\n", err)
52
return
53
}
54
55
nodeJSON, err := json.MarshalIndent(nodes, "", " ")
56
if err != nil {
57
fmt.Printf("Error marshaling to JSON: %v\n", err)
58
return
59
}
60
61
fmt.Println(string(nodeJSON))
62
63
}
Don't have an account yet?
Create your Quicknode endpoint in seconds and start building
Get started for free