gRPC «EstimateGasPriceAndUsage»
Parâmetros
tx_priority
cadeia de caracteres
OBRIGATÓRIO
Carregando...
TX_PRIORITY_UNSPECIFIED
número inteiro
Carregando...
TX_PRIORITY_LOW
número inteiro
Carregando...
TX_PRIORITY_MEDIUM
número inteiro
Carregando...
TX_PRIORITY_HIGH
número inteiro
Carregando...
tx_bytes
cadeia de caracteres
OBRIGATÓRIO
Carregando...
Devoluções
preço_estimado_da_gasolina
número inteiro
Carregando...
consumo_estimado_de_gás
número inteiro
Carregando...
Pedido
1pacote principal23importar (4"contexto"5"crypto/tls"6"encoding/json"7"fmt"8"registo"9"tempo"1011"google.golang.grpc"12"google.golang.grpc"1314estimativa de gás "celestia"15)1617// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token18// For eg: QN Endpoint: https://docs-demo.celestia-mainnet.quiknode.pro/abcde12345678919// endpoint will be: docs-demo.celestia-mainnet.quiknode.pro:9090 {9090 is the port number for Celestia gRPC}20// token will be : abcde1234567892122var token = "O_SEU_TOKEN"23var endpoint = "O_SEU_PONTO_DE_ACESSO:9090"2425tipo auth estrutura {26token cadeia de caracteres27}2829func (a *auth) GetRequestMetadata(ctx contexto.Context, uri ...string) (mapa[string]cadeia de caracteres, erro) {30retornar mapa[string]string{31«x-token»: um.token,32}, nil33}3435func (a *auth) RequireTransportSecurity() bool {36retornar false37}3839func main() {40opts := []grpc.DialOption{41grpc.WithTransportCredentials(credenciais.NewTLS(&tls.Config{})),42grpc.WithPerRPCCredentials(&auth{token}),43}4445// Create gRPC connection46conn, err := grpc.Dial(endpoint, opts...)47se err != nil {48registo.Fatalf("Falha ao ligar aogRPC Celestia : %v", err)49}50adiar conn.Fechar()5152cliente := estimativa de gás.NewGasEstimatorClient(conn)5354ctx, cancel := contexto.WithTimeout(contexto.Background(), 10*vez.Segundo)55adiar cancelar()5657// Example transaction bytes (this would be your actual transaction in practice)58txBytes := []byte("SIGNED_TRANSACTION_BYTES")5960resp, err := client.EstimateGasPriceAndUsage(ctx, &gasestimation.EstimateGasPriceAndUsageRequest{61TxPriority: estimativa de consumo de combustível.TxPriority_TX_PRIORITY_MEDIUM,62TxBytes: txBytes,63})64se err != nil {65registo.Fatalf("Falha na estimativa do preço e do consumo de gás: %v", err)66}6768jsonData, err := json.MarshalIndent(resp, "", " ")69se err != nil {70registo.Printf("Erro ao converter para JSON: %v", err)71} caso contrário {72fmt.Println("\nSaída:")73fmt.Println(string(jsonData))74}75}
1pacote principal23importar (4"contexto"5"crypto/tls"6"encoding/json"7"fmt"8"registo"9"tempo"1011"google.golang.grpc"12"google.golang.grpc"1314estimativa de gás "celestia"15)1617// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token18// For eg: QN Endpoint: https://docs-demo.celestia-mainnet.quiknode.pro/abcde12345678919// endpoint will be: docs-demo.celestia-mainnet.quiknode.pro:9090 {9090 is the port number for Celestia gRPC}20// token will be : abcde1234567892122var token = "O_SEU_TOKEN"23var endpoint = "O_SEU_PONTO_DE_ACESSO:9090"2425tipo auth estrutura {26token cadeia de caracteres27}2829func (a *auth) GetRequestMetadata(ctx contexto.Context, uri ...string) (mapa[string]cadeia de caracteres, erro) {30retornar mapa[string]string{31«x-token»: um.token,32}, nil33}3435func (a *auth) RequireTransportSecurity() bool {36retornar false37}3839func main() {40opts := []grpc.DialOption{41grpc.WithTransportCredentials(credenciais.NewTLS(&tls.Config{})),42grpc.WithPerRPCCredentials(&auth{token}),43}4445// Create gRPC connection46conn, err := grpc.Dial(endpoint, opts...)47se err != nil {48registo.Fatalf("Falha ao ligar aogRPC Celestia : %v", err)49}50adiar conn.Fechar()5152cliente := estimativa de gás.NewGasEstimatorClient(conn)5354ctx, cancel := contexto.WithTimeout(contexto.Background(), 10*vez.Segundo)55adiar cancelar()5657// Example transaction bytes (this would be your actual transaction in practice)58txBytes := []byte("SIGNED_TRANSACTION_BYTES")5960resp, err := client.EstimateGasPriceAndUsage(ctx, &gasestimation.EstimateGasPriceAndUsageRequest{61TxPriority: estimativa de consumo de combustível.TxPriority_TX_PRIORITY_MEDIUM,62TxBytes: txBytes,63})64se err != nil {65registo.Fatalf("Falha na estimativa do preço e do consumo de gás: %v", err)66}6768jsonData, err := json.MarshalIndent(resp, "", " ")69se err != nil {70registo.Printf("Erro ao converter para JSON: %v", err)71} caso contrário {72fmt.Println("\nSaída:")73fmt.Println(string(jsonData))74}75}
Ainda não tem uma conta?
Crieendpoint seuendpoint Quicknode endpoint segundos e comece a desenvolver
Comece gratuitamente