EstimateEnergy gRPC Method
पैरामीटर
से
डोरी
आवश्यक
लोड हो रहा है...
अनुबंध का पता
डोरी
आवश्यक
लोड हो रहा है...
method
डोरी
आवश्यक
लोड हो रहा है...
jsonString
डोरी
आवश्यक
लोड हो रहा है...
tAmount
पूर्णांक
आवश्यक
लोड हो रहा है...
tTokenID
डोरी
आवश्यक
लोड हो रहा है...
tTokenAmount
पूर्णांक
आवश्यक
लोड हो रहा है...
रिटर्न
परिणाम
वस्तु
लोड हो रहा है...
परिणाम
बूलियन
लोड हो रहा है...
code
डोरी
लोड हो रहा है...
संदेश
डोरी
लोड हो रहा है...
energy_required
पूर्णांक
लोड हो रहा है...
अनुरोध
1package main23import (4"context"5"crypto/tls"6"encoding/json"7"fmt"8"github.com/fbsobreira/gotron-sdk/pkg/client"9"google.golang.org/grpc"10"google.golang.org/grpc/credentials"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 = "YOUR_TOKEN"19var endpoint = "YOUR_ENDPOINT:50051"2021type auth struct {22token string23}2425func (a *auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {26return map[string]string{27"x-token": a.token,28}, nil29}3031func (a *auth) RequireTransportSecurity() bool {32return false33}3435func main() {3637opts := []grpc.DialOption{38grpc.WithTransportCredentials(credentials.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()4647from := "TTGhREx2pDSxFX555NWz1YwGpiBVPvQA7e"48contractAddress := "TVSvjZdyDSNocHm7dP3jvCmMNsCnMTPa5W"49method := "transfer(address,uint256)"50jsonString := `[{"address": "TE4c73WubeWPhSF1nAovQDmQytjcaLZyY9"},{"uint256": "100"}]`51tAmount := int64(0)52tTokenID := ""53tTokenAmount := int64(0)5455fmt.Println("Estimating energy for contract call...")5657energy, err := conn.EstimateEnergy(58from, // Caller's address59contractAddress, // Contract address60method, // Function selector61jsonString, // Parameters in JSON format62tAmount, // TRX value to send63tTokenID, // Token ID (if applicable)64tTokenAmount, // Token value (if applicable)65)6667if err != nil {68fmt.Printf("Error estimating energy: %v\n", err)69return70}7172fmt.Println("Energy estimation successful! Results:")73jsonData, _ := json.MarshalIndent(energy, "", " ")74fmt.Println(string(jsonData))7576if !energy.Result.Result {77fmt.Println("Energy estimation failed!")78if len(energy.Result.Message) > 0 {79fmt.Printf("Error message: %s\n", energy.Result.Message)80}81return82}8384energyRequired := energy.EnergyRequired85energyBuffer := energyRequired / 5 // Add 20% buffer86recommendedFeeLimit := (energyRequired + energyBuffer) * 4208788fmt.Printf("\nEstimated energy required: %d\n", energyRequired)89fmt.Printf("Recommended fee limit (with 20%% buffer): %d SUN\n", recommendedFeeLimit)90fmt.Println("\nYou can use this fee limit when making the actual transaction.")91}
1package main23import (4"context"5"crypto/tls"6"encoding/json"7"fmt"8"github.com/fbsobreira/gotron-sdk/pkg/client"9"google.golang.org/grpc"10"google.golang.org/grpc/credentials"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 = "YOUR_TOKEN"19var endpoint = "YOUR_ENDPOINT:50051"2021type auth struct {22token string23}2425func (a *auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {26return map[string]string{27"x-token": a.token,28}, nil29}3031func (a *auth) RequireTransportSecurity() bool {32return false33}3435func main() {3637opts := []grpc.DialOption{38grpc.WithTransportCredentials(credentials.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()4647from := "TTGhREx2pDSxFX555NWz1YwGpiBVPvQA7e"48contractAddress := "TVSvjZdyDSNocHm7dP3jvCmMNsCnMTPa5W"49method := "transfer(address,uint256)"50jsonString := `[{"address": "TE4c73WubeWPhSF1nAovQDmQytjcaLZyY9"},{"uint256": "100"}]`51tAmount := int64(0)52tTokenID := ""53tTokenAmount := int64(0)5455fmt.Println("Estimating energy for contract call...")5657energy, err := conn.EstimateEnergy(58from, // Caller's address59contractAddress, // Contract address60method, // Function selector61jsonString, // Parameters in JSON format62tAmount, // TRX value to send63tTokenID, // Token ID (if applicable)64tTokenAmount, // Token value (if applicable)65)6667if err != nil {68fmt.Printf("Error estimating energy: %v\n", err)69return70}7172fmt.Println("Energy estimation successful! Results:")73jsonData, _ := json.MarshalIndent(energy, "", " ")74fmt.Println(string(jsonData))7576if !energy.Result.Result {77fmt.Println("Energy estimation failed!")78if len(energy.Result.Message) > 0 {79fmt.Printf("Error message: %s\n", energy.Result.Message)80}81return82}8384energyRequired := energy.EnergyRequired85energyBuffer := energyRequired / 5 // Add 20% buffer86recommendedFeeLimit := (energyRequired + energyBuffer) * 4208788fmt.Printf("\nEstimated energy required: %d\n", energyRequired)89fmt.Printf("Recommended fee limit (with 20%% buffer): %d SUN\n", recommendedFeeLimit)90fmt.Println("\nYou can use this fee limit when making the actual transaction.")91}
अब तक कोई खाता नहीं है?
कुछ ही सेकंड में अपना क्विकनोड एंडपॉइंट बनाएं और निर्माण शुरू करें।
मुफ़्त में शुरुआत करें