EstimateGasPriceAndUsage gRPC Method
Parameters
tx_priority
string
REQUIRED
Loading...
tx_bytes
string
REQUIRED
Loading...
Returns
estimated_gas_price
integer
Loading...
estimated_gas_used
integer
Loading...
Request
package main import ( "context" "crypto/tls" "encoding/json" "fmt" "log" "time" "google.golang.org/grpc" "google.golang.org/grpc/credentials" gasestimation "celestia-grpc/celestia/core/v1/gas_estimation" ) // QuickNode endpoints consist of two crucial components: the endpoint name and the corresponding token // For eg: QN Endpoint: https://docs-demo.celestia-mainnet.quiknode.pro/abcde123456789 // endpoint will be: docs-demo.celestia-mainnet.quiknode.pro:9090 {9090 is the port number for Celestia gRPC} // token will be : abcde123456789 var token = "YOUR_TOKEN" var endpoint = "YOUR_ENDPOINT:9090" type auth struct { token string } func (a *auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) { return map[string]string{ "x-token": a.token, }, nil } func (a *auth) RequireTransportSecurity() bool { return false } func main() { opts := []grpc.DialOption{ grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})), grpc.WithPerRPCCredentials(&auth{token}), } // Create gRPC connection conn, err := grpc.Dial(endpoint, opts...) if err != nil { log.Fatalf("Failed to connect to Celestia gRPC server: %v", err) } defer conn.Close() client := gasestimation.NewGasEstimatorClient(conn) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() // Example transaction bytes (this would be your actual transaction in practice) txBytes := []byte("SIGNED_TRANSACTION_BYTES") resp, err := client.EstimateGasPriceAndUsage(ctx, &gasestimation.EstimateGasPriceAndUsageRequest{ TxPriority: gasestimation.TxPriority_TX_PRIORITY_MEDIUM, TxBytes: txBytes, }) if err != nil { log.Fatalf("Failed to estimate gas price and usage: %v", err) } jsonData, err := json.MarshalIndent(resp, "", " ") if err != nil { log.Printf("Error converting to JSON: %v", err) } else { fmt.Println("\nOutput:") fmt.Println(string(jsonData)) } }
Don't have an account yet?
Create your QuickNode endpoint in seconds and start building
Get started for free