EstimateGasPriceAndUsage gRPC Method
Parámetros
tx_priority
cadena
OBLIGATORIO
Cargando...
TX_PRIORITY_UNSPECIFIED
entero
Cargando...
TX_PRIORITY_LOW
entero
Cargando...
TX_PRIORITY_MEDIUM
entero
Cargando...
TX_PRIORITY_HIGH
entero
Cargando...
tx_bytes
cadena
OBLIGATORIO
Cargando...
Devoluciones
estimated_gas_price
entero
Cargando...
estimated_gas_used
entero
Cargando...
Solicitud
1paquete principal23import (4«contexto»5«crypto/tls»6«encoding/json»7«fmt»8«registro»9«tiempo»1011"google.golang.org/grpc"12"google.golang.org/grpc/credentials"1314gasestimation "celestia-grpc/celestia/core/v1/gas_estimation"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 = "TU_TOKEN"23var endpoint = "YOUR_ENDPOINT:9090"2425tipo autenticación estructura {26token cadena27}2829func (a *auth) GetRequestMetadata(ctx contexto.Context, uri ...cadena) (mapa[cadena]cadena, error) {30volver mapa[cadena]cadena{31«x-token»: un.token,32}, nil33}3435func (a *auth) RequireTransportSecurity() bool {36volver false37}3839func main() {40opts := []grpc.DialOption{41grpc.WithTransportCredentials(credenciales.NewTLS(&tls.Config{})),42grpc.Con credenciales RPCC(&auth{token}),43}4445// Create gRPC connection46conn, err := grpc.Dial(endpoint, opts...)47si err != nil {48log.Fatalf("Failed to connect to Celestia gRPC server: %v", err)49}50aplazar conn.Cerrar()5152client := gasestimation.NewGasEstimatorClient(conn)5354ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)55defer cancel()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: gasestimation.TxPriority_TX_PRIORITY_MEDIUM,62TxBytes: txBytes,63})64si err != nil {65log.Fatalf("Failed to estimate gas price and usage: %v", err)66}6768jsonData, err := json.MarshalIndent(resp, "", " ")69si err != nil {70log.Printf("Error converting to JSON: %v", err)71} else {72fmt.Println("\nOutput:")73fmt.Println(string(jsonData))74}75}
1paquete principal23import (4«contexto»5«crypto/tls»6«encoding/json»7«fmt»8«registro»9«tiempo»1011"google.golang.org/grpc"12"google.golang.org/grpc/credentials"1314gasestimation "celestia-grpc/celestia/core/v1/gas_estimation"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 = "TU_TOKEN"23var endpoint = "YOUR_ENDPOINT:9090"2425tipo autenticación estructura {26token cadena27}2829func (a *auth) GetRequestMetadata(ctx contexto.Context, uri ...cadena) (mapa[cadena]cadena, error) {30volver mapa[cadena]cadena{31«x-token»: un.token,32}, nil33}3435func (a *auth) RequireTransportSecurity() bool {36volver false37}3839func main() {40opts := []grpc.DialOption{41grpc.WithTransportCredentials(credenciales.NewTLS(&tls.Config{})),42grpc.Con credenciales RPCC(&auth{token}),43}4445// Create gRPC connection46conn, err := grpc.Dial(endpoint, opts...)47si err != nil {48log.Fatalf("Failed to connect to Celestia gRPC server: %v", err)49}50aplazar conn.Cerrar()5152client := gasestimation.NewGasEstimatorClient(conn)5354ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)55defer cancel()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: gasestimation.TxPriority_TX_PRIORITY_MEDIUM,62TxBytes: txBytes,63})64si err != nil {65log.Fatalf("Failed to estimate gas price and usage: %v", err)66}6768jsonData, err := json.MarshalIndent(resp, "", " ")69si err != nil {70log.Printf("Error converting to JSON: %v", err)71} else {72fmt.Println("\nOutput:")73fmt.Println(string(jsonData))74}75}
¿Aún no tienes una cuenta?
Crea tu punto de conexión de Quicknode en cuestión de segundos y empieza a desarrollar
Empieza gratis