GetCanDelegatedMaxSize gRPC Method
Parâmetros
morada
cadeia de caracteres
OBRIGATÓRIO
Carregando...
resource
número inteiro
OBRIGATÓRIO
Carregando...
Devoluções
max_size
número inteiro
Carregando...
Pedido
1pacote principal23importar (4"contexto"5"crypto/tls"6"fmt"7"github.com/fbsobreira/gotron-sdk/pkg/client"8"google.golang.grpc"9"google.golang.grpc"10"registo"11)1213// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token14// For eg: QN Endpoint: https://docs-demo.tron-mainnet.quiknode.pro/abcde12345678915// endpoint will be: docs-demo.tron-mainnet.quiknode.pro:50051 {50051 is the port number for Tron gRPC}16// token will be : abcde1234567891718var token = "O_SEU_TOKEN"19var endpoint = "YOUR_ENDPOINT:50051"2021tipo auth estrutura {22token cadeia de caracteres23}2425func (a *auth) GetRequestMetadata(ctx contexto.Context, uri ...string) (mapa[string]cadeia de caracteres, erro) {26retornar mapa[string]string{27«x-token»: um.token,28}, nil29}3031func (a *auth) RequireTransportSecurity() bool {32retornar false33}3435func main() {3637opts := []grpc.DialOption{38grpc.WithTransportCredentials(credenciais.NewTLS(&tls.Config{})),39grpc.WithPerRPCCredentials(&auth{token}),40}41conn := client.NewGrpcClient(endpoint)42if err := conn.Start(opts...); err != nil {43panic(err)44}45defer conn.Conn.Close()4647address := "TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g" // // Address to check48resource := int32(0) //Resource type: 0 for bandwidth, 1 for energy (using int32 as required)4950fmt.Printf("Checking max delegatable bandwidth for address: %s\n", address)51// Call GetCanDelegatedMaxSize for bandwidth52bandwidthMax, err := conn.GetCanDelegatedMaxSize(address, resource)53se err != nil {54log.Printf("Error getting max delegatable bandwidth: %v\n", err)55} caso contrário {56fmt.Printf("Max delegatable bandwidth: %d\n", bandwidthMax)57}5859// Check energy too60resource = int32(1) // Energy61fmt.Printf("\nChecking max delegatable energy for address: %s\n", address)62energyMax, err := conn.GetCanDelegatedMaxSize(address, resource)63se err != nil {64log.Printf("Error getting max delegatable energy: %v\n", err)65} caso contrário {66fmt.Printf("Max delegatable energy: %d\n", energyMax)67}68}
1pacote principal23importar (4"contexto"5"crypto/tls"6"fmt"7"github.com/fbsobreira/gotron-sdk/pkg/client"8"google.golang.grpc"9"google.golang.grpc"10"registo"11)1213// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token14// For eg: QN Endpoint: https://docs-demo.tron-mainnet.quiknode.pro/abcde12345678915// endpoint will be: docs-demo.tron-mainnet.quiknode.pro:50051 {50051 is the port number for Tron gRPC}16// token will be : abcde1234567891718var token = "O_SEU_TOKEN"19var endpoint = "YOUR_ENDPOINT:50051"2021tipo auth estrutura {22token cadeia de caracteres23}2425func (a *auth) GetRequestMetadata(ctx contexto.Context, uri ...string) (mapa[string]cadeia de caracteres, erro) {26retornar mapa[string]string{27«x-token»: um.token,28}, nil29}3031func (a *auth) RequireTransportSecurity() bool {32retornar false33}3435func main() {3637opts := []grpc.DialOption{38grpc.WithTransportCredentials(credenciais.NewTLS(&tls.Config{})),39grpc.WithPerRPCCredentials(&auth{token}),40}41conn := client.NewGrpcClient(endpoint)42if err := conn.Start(opts...); err != nil {43panic(err)44}45defer conn.Conn.Close()4647address := "TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g" // // Address to check48resource := int32(0) //Resource type: 0 for bandwidth, 1 for energy (using int32 as required)4950fmt.Printf("Checking max delegatable bandwidth for address: %s\n", address)51// Call GetCanDelegatedMaxSize for bandwidth52bandwidthMax, err := conn.GetCanDelegatedMaxSize(address, resource)53se err != nil {54log.Printf("Error getting max delegatable bandwidth: %v\n", err)55} caso contrário {56fmt.Printf("Max delegatable bandwidth: %d\n", bandwidthMax)57}5859// Check energy too60resource = int32(1) // Energy61fmt.Printf("\nChecking max delegatable energy for address: %s\n", address)62energyMax, err := conn.GetCanDelegatedMaxSize(address, resource)63se err != nil {64log.Printf("Error getting max delegatable energy: %v\n", err)65} caso contrário {66fmt.Printf("Max delegatable energy: %d\n", energyMax)67}68}
Ainda não tem uma conta?
Crieendpoint seuendpoint Quicknode endpoint segundos e comece a desenvolver
Comece gratuitamente