UpdateHash gRPC Method
參數
tx
物件
必填
載入中...
transaction
物件
載入中...
txid
字串
載入中...
constant_result
陣列
載入中...
結果
物件
載入中...
退貨
錯誤
物件
載入中...
請求
1套件 主函式23匯入 (4"上下文"5"crypto/tls"6"fmt"7"encoding/json"89"github.com/fbsobreira/gotron-sdk/pkg/client"10"google.golang.grpc"11"google.golang.grpc"12)131415// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token16// For eg: QN Endpoint: https://docs-demo.tron-mainnet.quiknode.pro/abcde12345678917// endpoint will be: docs-demo.tron-mainnet.quiknode.pro:50051 {50051 is the port number for Tron gRPC}18// token will be : abcde1234567891920var 代幣 = "您的_代幣"21var endpoint = "YOUR_ENDPOINT:50051"222324類型 auth 結構體 {25代幣 字串26}2728func (a *auth) GetRequestMetadata(ctx 上下文.Context, uri ...字串) (map[字串]字串, 錯誤) {29返回 地圖[字串]字串{30「x-token」: a.token,31}, nil32}3334func (a *auth) RequireTransportSecurity() bool {35返回 false36}3738func main() {39opts := []grpc.DialOption{40grpc.WithTransportCredentials(憑證.NewTLS(&tls.Config{})),41grpc.WithPerRPC憑證(&auth{token}),42}43conn := client.NewGrpcClient(endpoint)44if err := conn.Start(opts...); err != nil {45panic(err)46}47defer conn.Conn.Close()4849fromAddress := "TC7xSvcMqW7PXuZXAuzhie81g22fA45kyY"50toAddress := "TTW663tQYJTTCtHh6DWKAfexRhPMf2DxQ1"51amount := int64(1000000)5253tx, err := conn.Transfer(fromAddress, toAddress, amount)54如果 err != nil {55fmt.Printf("Error creating transfer transaction: %v\n", err)56return57}58fmt.Printf("Transaction ID before UpdateHash: %x\n", tx.Txid)5960err = conn.UpdateHash(tx)61如果 err != nil {62fmt.Printf("Error calling UpdateHash: %v\n", err)63return64}6566fmt.Println("Transaction after UpdateHash:")6768jsonData, err := json.MarshalIndent(tx, "", " ")69如果 err != nil {70fmt.Printf("Error marshaling to JSON: %v\n", err)71return72}7374fmt.Println(string(jsonData))75}
1套件 主函式23匯入 (4"上下文"5"crypto/tls"6"fmt"7"encoding/json"89"github.com/fbsobreira/gotron-sdk/pkg/client"10"google.golang.grpc"11"google.golang.grpc"12)131415// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token16// For eg: QN Endpoint: https://docs-demo.tron-mainnet.quiknode.pro/abcde12345678917// endpoint will be: docs-demo.tron-mainnet.quiknode.pro:50051 {50051 is the port number for Tron gRPC}18// token will be : abcde1234567891920var 代幣 = "您的_代幣"21var endpoint = "YOUR_ENDPOINT:50051"222324類型 auth 結構體 {25代幣 字串26}2728func (a *auth) GetRequestMetadata(ctx 上下文.Context, uri ...字串) (map[字串]字串, 錯誤) {29返回 地圖[字串]字串{30「x-token」: a.token,31}, nil32}3334func (a *auth) RequireTransportSecurity() bool {35返回 false36}3738func main() {39opts := []grpc.DialOption{40grpc.WithTransportCredentials(憑證.NewTLS(&tls.Config{})),41grpc.WithPerRPC憑證(&auth{token}),42}43conn := client.NewGrpcClient(endpoint)44if err := conn.Start(opts...); err != nil {45panic(err)46}47defer conn.Conn.Close()4849fromAddress := "TC7xSvcMqW7PXuZXAuzhie81g22fA45kyY"50toAddress := "TTW663tQYJTTCtHh6DWKAfexRhPMf2DxQ1"51amount := int64(1000000)5253tx, err := conn.Transfer(fromAddress, toAddress, amount)54如果 err != nil {55fmt.Printf("Error creating transfer transaction: %v\n", err)56return57}58fmt.Printf("Transaction ID before UpdateHash: %x\n", tx.Txid)5960err = conn.UpdateHash(tx)61如果 err != nil {62fmt.Printf("Error calling UpdateHash: %v\n", err)63return64}6566fmt.Println("Transaction after UpdateHash:")6768jsonData, err := json.MarshalIndent(tx, "", " ")69如果 err != nil {70fmt.Printf("Error marshaling to JSON: %v\n", err)71return72}7374fmt.Println(string(jsonData))75}