EstimateEnergy gRPC Method
Parâmetros
de
cadeia de caracteres
OBRIGATÓRIO
A carregar...
contractAddress
cadeia de caracteres
OBRIGATÓRIO
A carregar...
method
cadeia de caracteres
OBRIGATÓRIO
A carregar...
jsonString
cadeia de caracteres
OBRIGATÓRIO
A carregar...
tAmount
número inteiro
OBRIGATÓRIO
A carregar...
tTokenID
cadeia de caracteres
OBRIGATÓRIO
A carregar...
tTokenAmount
número inteiro
OBRIGATÓRIO
A carregar...
Devoluções
resultado
objeto
A carregar...
resultado
booleano
A carregar...
código
cadeia de caracteres
A carregar...
mensagem
cadeia de caracteres
A carregar...
energy_required
número inteiro
A carregar...
Pedido
1pacote principal23importar (4"contexto"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 ponto final = "O_SEU_PONTO_DE_ACESSO:50051"2021tipo auth estrutura {22token cadeia de caracteres23}2425func (a *auth) GetRequestMetadata(ctx contexto.Context, uri ...string) (mapa[string]string, erro) {26retornar mapa[string]string{27"x-token": a.token,28}, nil29}3031func (a *auth) RequireTransportSecurity() bool {32retornar false33}3435func main() {3637opts := []grpc.DialOption{38grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),39grpc.WithPerRPCCredentials(&auth{token}),40}41conn := cliente.NewGrpcClient(ponto de extremidade)42if err := conn.Start(opts...); err != nil {43panic(err)44}45adiar conn.Conn.Fechar()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)6667se 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}
1pacote principal23importar (4"contexto"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 ponto final = "O_SEU_PONTO_DE_ACESSO:50051"2021tipo auth estrutura {22token cadeia de caracteres23}2425func (a *auth) GetRequestMetadata(ctx contexto.Context, uri ...string) (mapa[string]string, erro) {26retornar mapa[string]string{27"x-token": a.token,28}, nil29}3031func (a *auth) RequireTransportSecurity() bool {32retornar false33}3435func main() {3637opts := []grpc.DialOption{38grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),39grpc.WithPerRPCCredentials(&auth{token}),40}41conn := cliente.NewGrpcClient(ponto de extremidade)42if err := conn.Start(opts...); err != nil {43panic(err)44}45adiar conn.Conn.Fechar()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)6667se 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}
Ainda não tem uma conta?
Crie o seu ponto de extremidade Quicknode em segundos e comece a desenvolver
Comece gratuitamente