Skip to main content

SetTimeout gRPC Method

Loading...

Updated on
May 13, 2025

SetTimeout gRPC Method

Parameters

timeout
integer
REQUIRED
Loading...

Returns

error
string
Loading...
Request
1
package main
2
3
import (
4
"context"
5
"crypto/tls"
6
"fmt"
7
"time"
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
conn := client.NewGrpcClient(endpoint)
40
41
conn.SetTimeout(10 * time.Second)
42
43
fmt.Println("Timeout set to 10 seconds")
44
45
opts := []grpc.DialOption{
46
grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),
47
grpc.WithPerRPCCredentials(&auth{token}),
48
}
49
50
if err := conn.Start(opts...); err != nil {
51
panic(err)
52
}
53
defer conn.Conn.Close()
54
55
fmt.Println("Client successfully started with custom timeout configuration")
56
57
}
Don't have an account yet?
Create your Quicknode endpoint in seconds and start building
Get started for free