Skip to main content

Stop gRPC Method

Loading...

Updated on
May 13, 2025

Stop gRPC Method

Parameters

This method does not accept any parameters

Returns

error
string
Loading...
Request
1
package main
2
3
import (
4
"context"
5
"crypto/tls"
6
"fmt"
7
8
"github.com/fbsobreira/gotron-sdk/pkg/client"
9
"google.golang.org/grpc"
10
"google.golang.org/grpc/credentials"
11
)
12
13
14
// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token
15
// For eg: QN Endpoint: https://docs-demo.tron-mainnet.quiknode.pro/abcde123456789
16
// endpoint will be: docs-demo.tron-mainnet.quiknode.pro:50051 {50051 is the port number for Tron gRPC}
17
// token will be : abcde123456789
18
19
var token = "YOUR_TOKEN"
20
var endpoint = "YOUR_ENDPOINT:50051"
21
22
23
type auth struct {
24
token string
25
}
26
27
func (a *auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
28
return map[string]string{
29
"x-token": a.token,
30
}, nil
31
}
32
33
func (a *auth) RequireTransportSecurity() bool {
34
return false
35
}
36
37
func main() {
38
opts := []grpc.DialOption{
39
grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),
40
grpc.WithPerRPCCredentials(&auth{token}),
41
}
42
conn := client.NewGrpcClient(endpoint)
43
if err := conn.Start(opts...); err != nil {
44
panic(err)
45
}
46
47
fmt.Println("Client successfully started")
48
49
fmt.Println("Performing operations...")
50
51
fmt.Println("Operations completed, stopping client...")
52
conn.Stop()
53
54
fmt.Println("Client stopped successfully")
55
56
fmt.Println("Restarting client...")
57
if err := conn.Start(opts...); err != nil {
58
panic(err)
59
}
60
fmt.Println("Client restarted successfully")
61
62
conn.Stop()
63
fmt.Println("Client stopped again")
64
65
}
Don't have an account yet?
Create your Quicknode endpoint in seconds and start building
Get started for free