EstimateGasPriceAndUsage gRPC Method
Paramètres
tx_priority
chaîne de caractères
OBLIGATOIRE
Chargement en cours...
TX_PRIORITY_UNSPECIFIED
entier
Chargement en cours...
TX_PRIORITY_LOW
entier
Chargement en cours...
TX_PRIORITY_MEDIUM
entier
Chargement en cours...
TX_PRIORITY_HIGH
entier
Chargement en cours...
tx_bytes
chaîne de caractères
OBLIGATOIRE
Chargement en cours...
Retours
estimated_gas_price
entier
Chargement en cours...
estimated_gas_used
entier
Chargement en cours...
Demande
1paquet principal23import (4« contexte »5« crypto/tls »6« encoding/json »7« fmt »8« journal »9« temps »1011« google.golang.grpc »12« google.golang.grpc »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 jeton = "VOTRE_TOKEN"23var endpoint = "VOTRE_POINT_D'ACCÈS:9090"2425type auth struct {26jeton chaîne de caractères27}2829func (a *auth) GetRequestMetadata(ctx contexte.Context, uri ...chaîne) (carte[chaîne]chaîne, erreur) {30retour carte[chaîne]chaîne{31« x-token »: un.jeton,32}, nil33}3435func (a *auth) RequireTransportSecurity() bool {36retour false37}3839func main() {40opts := []grpc.DialOption{41grpc.WithTransportCredentials(informations d'authentification.NewTLS(&tls.Config{})),42grpc.Avec les identifiants RPCC(&auth{token}),43}4445// Create gRPC connection46conn, err := grpc.Composer(endpoint, opts...)47si err != nil {48journal.Fatalf(« Échec de la connexion augRPC Celestia : %v », err)49}50reporter conn.Fermer()5152client := gasestimation.NewGasEstimatorClient(conn)5354ctx, annuler := context.WithTimeout(contexte.Arrière-plan(), 10*temps.Deuxième)55reporter annuler()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} sinon {72fmt.Println("\nOutput:")73fmt.Println(chaîne(jsonData)))74}75}
1paquet principal23import (4« contexte »5« crypto/tls »6« encoding/json »7« fmt »8« journal »9« temps »1011« google.golang.grpc »12« google.golang.grpc »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 jeton = "VOTRE_TOKEN"23var endpoint = "VOTRE_POINT_D'ACCÈS:9090"2425type auth struct {26jeton chaîne de caractères27}2829func (a *auth) GetRequestMetadata(ctx contexte.Context, uri ...chaîne) (carte[chaîne]chaîne, erreur) {30retour carte[chaîne]chaîne{31« x-token »: un.jeton,32}, nil33}3435func (a *auth) RequireTransportSecurity() bool {36retour false37}3839func main() {40opts := []grpc.DialOption{41grpc.WithTransportCredentials(informations d'authentification.NewTLS(&tls.Config{})),42grpc.Avec les identifiants RPCC(&auth{token}),43}4445// Create gRPC connection46conn, err := grpc.Composer(endpoint, opts...)47si err != nil {48journal.Fatalf(« Échec de la connexion augRPC Celestia : %v », err)49}50reporter conn.Fermer()5152client := gasestimation.NewGasEstimatorClient(conn)5354ctx, annuler := context.WithTimeout(contexte.Arrière-plan(), 10*temps.Deuxième)55reporter annuler()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} sinon {72fmt.Println("\nOutput:")73fmt.Println(chaîne(jsonData)))74}75}
Vous n'avez pas encore de compte ?
Créez votreendpoint Quicknode endpoint quelques secondes et commencez à développer
Commencez gratuitement