FreezeBalanceV2 gRPC Method
パラメータ
出典
文字列
必須
読み込み中...
resource
文字列
必須
読み込み中...
frozenBalance
整数
必須
読み込み中...
返します
取引
オブジェクト
読み込み中...
raw_data
オブジェクト
読み込み中...
ref_block_bytes
文字列
読み込み中...
ref_block_num
整数
読み込み中...
ref_block_hash
文字列
読み込み中...
有効期限
整数
読み込み中...
auths
配列
読み込み中...
データ
文字列
読み込み中...
契約
配列
読み込み中...
タイプ
文字列
読み込み中...
パラメータ
オブジェクト
読み込み中...
値
文字列
読み込み中...
type_url
文字列
読み込み中...
provider
文字列
読み込み中...
ContractName
文字列
読み込み中...
Permission_id
整数
読み込み中...
scripts
文字列
読み込み中...
タイムスタンプ
整数
読み込み中...
fee_limit
整数
読み込み中...
署名
配列
読み込み中...
ret
配列
読み込み中...
手数料
整数
読み込み中...
ret
文字列
読み込み中...
contractRet
文字列
読み込み中...
assetIssueID
文字列
読み込み中...
withdraw_amount
整数
読み込み中...
unfreeze_amount
整数
読み込み中...
exchange_received_amount
整数
読み込み中...
exchange_inject_another_amount
整数
読み込み中...
exchange_withdraw_another_amount
整数
読み込み中...
exchange_id
整数
読み込み中...
shielded_transaction_fee
整数
読み込み中...
orderId
文字列
読み込み中...
orderDetails
配列
読み込み中...
makerOrderId
文字列
読み込み中...
takerOrderId
文字列
読み込み中...
fillSellQuantity
整数
読み込み中...
fillBuyQuantity
整数
読み込み中...
withdraw_expire_amount
整数
読み込み中...
cancelUnfreezeV2Amount
オブジェクト
読み込み中...
txid
文字列
読み込み中...
定数_結果
配列
読み込み中...
結果
オブジェクト
読み込み中...
結果
ブール値
読み込み中...
コード
文字列
読み込み中...
メッセージ
文字列
読み込み中...
エネルギー消費量
整数
読み込み中...
logs
配列
読み込み中...
住所
文字列
読み込み中...
トピック
配列
読み込み中...
データ
文字列
読み込み中...
internal_transactions
配列
読み込み中...
ハッシュ
文字列
読み込み中...
caller_address
文字列
読み込み中...
transferTo_address
文字列
読み込み中...
callValueInfo
配列
読み込み中...
callValue
整数
読み込み中...
tokenId
文字列
読み込み中...
note
文字列
読み込み中...
rejected
ブール値
読み込み中...
extra
文字列
読み込み中...
energy_penalty
整数
読み込み中...
リクエスト
1パッケージ main23インポート (4「文脈」5"crypto/tls"6"encoding/json"7"fmt"8"github.com/fbsobreira/gotron-sdk/pkg/client"9"github.com/fbsobreira/gotron-sdk/pkg/proto/core"10"google.golang.grpc"11"google.golang.grpc"12)1314// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token15// For eg: QN Endpoint: https://docs-demo.tron-mainnet.quiknode.pro/abcde12345678916// endpoint will be: docs-demo.tron-mainnet.quiknode.pro:50051 {50051 is the port number for Tron gRPC}17// token will be : abcde1234567891819var トークン = "YOUR_TOKEN"20var endpoint = "YOUR_ENDPOINT:50051"2122タイプ auth 構造体 {23token string24}2526func (a *auth) GetRequestMetadata(ctx コンテキスト.Context, uri ...文字列) (map[文字列]文字列, エラー) {27return map[string]string{28"x-token": a.token,29}, nil30}3132func (a *auth) RequireTransportSecurity(auth) bool {33return false34}3536// Convert SUN to TRX for display (1 TRX = 1,000,000 SUN)37func sunToTrx(sun int64) float64 {38return float64(sun) / 1000000.039}4041func main() {42/*43* 1. The FreezeBalanceV2 method is the upgraded version of FreezeBalance for obtaining resources.44* 2. Unlike V1, frozen TRX using V2 can be unfrozen at any time without a waiting period.45* 3. V2 does not support delegating resources to other accounts directly (use DelegateResource instead).46* 4. The account must have sufficient TRX balance for the freeze operation.47* 5. The transaction must be signed before broadcasting to the network.48* 6. FreezeBalanceV2 is the recommended method for obtaining resources in newer Tron versions.49*/5051opts := []grpc.DialOption{52grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),53grpc.WithPerRPCCredentials(&auth{token}),54}55conn := client.NewGrpcClient(endpoint)56if err := conn.Start(opts...); err != nil {57panic(err)58}59defer conn.Conn.Close()6061from := "TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g" // Address that is freezing TRX62resource := core.ResourceCode_BANDWIDTH // Resource type (BANDWIDTH or ENERGY)63frozenBalance := int64(10000000) // Amount of TRX to freeze in SUN (10 TRX)6465resourceName := "BANDWIDTH"66if resource == core.ResourceCode_ENERGY {67resourceName = "ENERGY"68}6970fmt.Printf("Checking balance for account %s...\n", from)71account, err := conn.GetAccount(from)72if err != nil {73fmt.Printf("Error getting account: %v\n", err)74return75}7677currentBalance := account.GetBalance()78fmt.Printf("Current balance: %d SUN (%.6f TRX)\n", currentBalance, sunToTrx(currentBalance))7980if currentBalance < frozenBalance {81fmt.Printf("Error: Insufficient balance. Have: %d SUN (%.6f TRX), Need: %d SUN (%.6f TRX)\n",82currentBalance, sunToTrx(currentBalance), frozenBalance, sunToTrx(frozenBalance))83if currentBalance > 1000000 { // At least 1 TRX available84suggestedAmount := (currentBalance / 1000000) * 1000000 // Round down to nearest TRX85fmt.Printf("\nAdjusting freeze amount to %d SUN (%.0f TRX) based on available balance\n",86suggestedAmount, sunToTrx(suggestedAmount))87frozenBalance = suggestedAmount88} else {89fmt.Println("\nYour balance is too low to freeze any meaningful amount of TRX.")90fmt.Println("Please add more TRX to your account and try again.")91return92}93}9495fmt.Printf("Freezing %d SUN (%.6f TRX) to obtain %s resources\n",96frozenBalance, sunToTrx(frozenBalance), resourceName)9798fmt.Println("Creating freeze balance V2 transaction...")99100tx, err := conn.FreezeBalanceV2(101from, // From address102resource, // Resource type (BANDWIDTH or ENERGY)103frozenBalance, // Amount to freeze in SUN104)105106if err != nil {107fmt.Printf("Error creating freeze transaction: %v\n", err)108return109}110111fmt.Println("Freeze transaction created successfully. Transaction details:")112jsonData, _ := json.MarshalIndent(tx, "", " ")113fmt.Println(string(jsonData))114115// Broadcast the transaction116fmt.Println("\nBroadcasting transaction to the TRON network...")117result, err := conn.Broadcast(tx.Transaction)118if err != nil {119fmt.Printf("Error broadcasting transaction: %v\n", err)120return121}122123if !result.GetResult() {124fmt.Printf("Broadcast failed: %s\n", result.GetMessage())125return126}127128fmt.Println("TRX frozen successfully using V2! Result:")129resultJSON, _ := json.MarshalIndent(result, "", " ")130fmt.Println(string(resultJSON))131}
1パッケージ main23インポート (4「文脈」5"crypto/tls"6"encoding/json"7"fmt"8"github.com/fbsobreira/gotron-sdk/pkg/client"9"github.com/fbsobreira/gotron-sdk/pkg/proto/core"10"google.golang.grpc"11"google.golang.grpc"12)1314// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token15// For eg: QN Endpoint: https://docs-demo.tron-mainnet.quiknode.pro/abcde12345678916// endpoint will be: docs-demo.tron-mainnet.quiknode.pro:50051 {50051 is the port number for Tron gRPC}17// token will be : abcde1234567891819var トークン = "YOUR_TOKEN"20var endpoint = "YOUR_ENDPOINT:50051"2122タイプ auth 構造体 {23token string24}2526func (a *auth) GetRequestMetadata(ctx コンテキスト.Context, uri ...文字列) (map[文字列]文字列, エラー) {27return map[string]string{28"x-token": a.token,29}, nil30}3132func (a *auth) RequireTransportSecurity(auth) bool {33return false34}3536// Convert SUN to TRX for display (1 TRX = 1,000,000 SUN)37func sunToTrx(sun int64) float64 {38return float64(sun) / 1000000.039}4041func main() {42/*43* 1. The FreezeBalanceV2 method is the upgraded version of FreezeBalance for obtaining resources.44* 2. Unlike V1, frozen TRX using V2 can be unfrozen at any time without a waiting period.45* 3. V2 does not support delegating resources to other accounts directly (use DelegateResource instead).46* 4. The account must have sufficient TRX balance for the freeze operation.47* 5. The transaction must be signed before broadcasting to the network.48* 6. FreezeBalanceV2 is the recommended method for obtaining resources in newer Tron versions.49*/5051opts := []grpc.DialOption{52grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),53grpc.WithPerRPCCredentials(&auth{token}),54}55conn := client.NewGrpcClient(endpoint)56if err := conn.Start(opts...); err != nil {57panic(err)58}59defer conn.Conn.Close()6061from := "TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g" // Address that is freezing TRX62resource := core.ResourceCode_BANDWIDTH // Resource type (BANDWIDTH or ENERGY)63frozenBalance := int64(10000000) // Amount of TRX to freeze in SUN (10 TRX)6465resourceName := "BANDWIDTH"66if resource == core.ResourceCode_ENERGY {67resourceName = "ENERGY"68}6970fmt.Printf("Checking balance for account %s...\n", from)71account, err := conn.GetAccount(from)72if err != nil {73fmt.Printf("Error getting account: %v\n", err)74return75}7677currentBalance := account.GetBalance()78fmt.Printf("Current balance: %d SUN (%.6f TRX)\n", currentBalance, sunToTrx(currentBalance))7980if currentBalance < frozenBalance {81fmt.Printf("Error: Insufficient balance. Have: %d SUN (%.6f TRX), Need: %d SUN (%.6f TRX)\n",82currentBalance, sunToTrx(currentBalance), frozenBalance, sunToTrx(frozenBalance))83if currentBalance > 1000000 { // At least 1 TRX available84suggestedAmount := (currentBalance / 1000000) * 1000000 // Round down to nearest TRX85fmt.Printf("\nAdjusting freeze amount to %d SUN (%.0f TRX) based on available balance\n",86suggestedAmount, sunToTrx(suggestedAmount))87frozenBalance = suggestedAmount88} else {89fmt.Println("\nYour balance is too low to freeze any meaningful amount of TRX.")90fmt.Println("Please add more TRX to your account and try again.")91return92}93}9495fmt.Printf("Freezing %d SUN (%.6f TRX) to obtain %s resources\n",96frozenBalance, sunToTrx(frozenBalance), resourceName)9798fmt.Println("Creating freeze balance V2 transaction...")99100tx, err := conn.FreezeBalanceV2(101from, // From address102resource, // Resource type (BANDWIDTH or ENERGY)103frozenBalance, // Amount to freeze in SUN104)105106if err != nil {107fmt.Printf("Error creating freeze transaction: %v\n", err)108return109}110111fmt.Println("Freeze transaction created successfully. Transaction details:")112jsonData, _ := json.MarshalIndent(tx, "", " ")113fmt.Println(string(jsonData))114115// Broadcast the transaction116fmt.Println("\nBroadcasting transaction to the TRON network...")117result, err := conn.Broadcast(tx.Transaction)118if err != nil {119fmt.Printf("Error broadcasting transaction: %v\n", err)120return121}122123if !result.GetResult() {124fmt.Printf("Broadcast failed: %s\n", result.GetMessage())125return126}127128fmt.Println("TRX frozen successfully using V2! Result:")129resultJSON, _ := json.MarshalIndent(result, "", " ")130fmt.Println(string(resultJSON))131}