FreezeBalance gRPC Method
参数
来自
字符串
必填
正在加载...
delegateTo
字符串
必填
正在加载...
resource
字符串
必填
正在加载...
frozenBalance
整数
必填
正在加载...
退货
交易
对象
正在加载...
raw_data
对象
正在加载...
ref_block_bytes
字符串
正在加载...
ref_block_num
整数
正在加载...
ref_block_hash
字符串
正在加载...
到期
整数
正在加载...
auths
数组
正在加载...
数据
字符串
正在加载...
合同
数组
正在加载...
类型
字符串
正在加载...
parameter
对象
正在加载...
值
字符串
正在加载...
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
字符串
正在加载...
constant_result
数组
正在加载...
结果
对象
正在加载...
结果
布尔型
正在加载...
代码
字符串
正在加载...
消息
字符串
正在加载...
energy_used
整数
正在加载...
日志
数组
正在加载...
地址
字符串
正在加载...
主题
数组
正在加载...
数据
字符串
正在加载...
internal_transactions
数组
正在加载...
哈希
字符串
正在加载...
caller_address
字符串
正在加载...
transferTo_address
字符串
正在加载...
callValueInfo
数组
正在加载...
callValue
整数
正在加载...
tokenId
字符串
正在加载...
note
字符串
正在加载...
rejected
布尔型
正在加载...
额外
字符串
正在加载...
energy_penalty
整数
正在加载...
请求
1包 main23import (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[字符串]字符串, error) {27return map[string]string{28"x-token": a.token,29}, nil30}3132func (a *auth) RequireTransportSecurity() 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() {4243opts := []grpc.DialOption{44grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),45grpc.WithPerRPCCredentials(&auth{token}),46}47conn := client.NewGrpcClient(endpoint)48if err := conn.Start(opts...); err != nil {49panic(err)50}51defer conn.Conn.Close()5253from := "TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g"54delegateTo := ""55resource := core.ResourceCode_BANDWIDTH56frozenBalance := int64(10000000)5758resourceName := "BANDWIDTH"59if resource == core.ResourceCode_ENERGY {60resourceName = "ENERGY"61}6263fmt.Printf("Checking balance for account %s...\n", from)64account, err := conn.GetAccount(from)65if err != nil {66fmt.Printf("Error getting account: %v\n", err)67返回68}6970currentBalance := account.GetBalance()71fmt.Printf("Current balance: %d SUN (%.6f TRX)\n", currentBalance, sunToTrx(currentBalance))7273if currentBalance < frozenBalance {74fmt.Printf("Error: Insufficient balance. Have: %d SUN (%.6f TRX), Need: %d SUN (%.6f TRX)\n",75currentBalance, sunToTrx(currentBalance), frozenBalance, sunToTrx(frozenBalance))76if currentBalance > 1000000 { // At least 1 TRX available77suggestedAmount := (currentBalance / 1000000) * 1000000 // Round down to nearest TRX78fmt.Printf("\nAdjusting freeze amount to %d SUN (%.0f TRX) based on available balance\n",79suggestedAmount, sunToTrx(suggestedAmount))80frozenBalance = suggestedAmount81} else {82fmt.Println("\nYour balance is too low to freeze any meaningful amount of TRX.")83fmt.Println("Please add more TRX to your account and try again.")84返回85}86}8788if delegateTo == "" {89fmt.Printf("Freezing %d SUN (%.6f TRX) to obtain %s resources for own account\n",90frozenBalance, sunToTrx(frozenBalance), resourceName)91} else {92fmt.Printf("Freezing %d SUN (%.6f TRX) to delegate %s resources to account %s\n",93frozenBalance, sunToTrx(frozenBalance), resourceName, delegateTo)94}9596fmt.Println("Creating freeze balance transaction...")9798tx, err := conn.FreezeBalance(99from, // From address100delegateTo, // Delegate to address (empty for self)101resource, // Resource type (BANDWIDTH or ENERGY)102frozenBalance, // Amount to freeze in SUN103)104105if err != nil {106fmt.Printf("Error creating freeze transaction: %v\n", err)107返回108}109110fmt.Println("Freeze transaction created successfully. Transaction details:")111jsonData, _ := json.MarshalIndent(tx, "", " ")112fmt.Println(string(jsonData))113114// Broadcast the transaction115fmt.Println("\nBroadcasting transaction to the TRON network...")116result, err := conn.Broadcast(tx.Transaction)117if err != nil {118fmt.Printf("Error broadcasting transaction: %v\n", err)119返回120}121122if !result.GetResult() {123fmt.Printf("Broadcast failed: %s\n", result.GetMessage())124返回125}126127fmt.Println("TRX frozen successfully! Result:")128resultJSON, _ := json.MarshalIndent(result, "", " ")129fmt.Println(string(resultJSON))130}
1包 main23import (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[字符串]字符串, error) {27return map[string]string{28"x-token": a.token,29}, nil30}3132func (a *auth) RequireTransportSecurity() 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() {4243opts := []grpc.DialOption{44grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),45grpc.WithPerRPCCredentials(&auth{token}),46}47conn := client.NewGrpcClient(endpoint)48if err := conn.Start(opts...); err != nil {49panic(err)50}51defer conn.Conn.Close()5253from := "TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g"54delegateTo := ""55resource := core.ResourceCode_BANDWIDTH56frozenBalance := int64(10000000)5758resourceName := "BANDWIDTH"59if resource == core.ResourceCode_ENERGY {60resourceName = "ENERGY"61}6263fmt.Printf("Checking balance for account %s...\n", from)64account, err := conn.GetAccount(from)65if err != nil {66fmt.Printf("Error getting account: %v\n", err)67返回68}6970currentBalance := account.GetBalance()71fmt.Printf("Current balance: %d SUN (%.6f TRX)\n", currentBalance, sunToTrx(currentBalance))7273if currentBalance < frozenBalance {74fmt.Printf("Error: Insufficient balance. Have: %d SUN (%.6f TRX), Need: %d SUN (%.6f TRX)\n",75currentBalance, sunToTrx(currentBalance), frozenBalance, sunToTrx(frozenBalance))76if currentBalance > 1000000 { // At least 1 TRX available77suggestedAmount := (currentBalance / 1000000) * 1000000 // Round down to nearest TRX78fmt.Printf("\nAdjusting freeze amount to %d SUN (%.0f TRX) based on available balance\n",79suggestedAmount, sunToTrx(suggestedAmount))80frozenBalance = suggestedAmount81} else {82fmt.Println("\nYour balance is too low to freeze any meaningful amount of TRX.")83fmt.Println("Please add more TRX to your account and try again.")84返回85}86}8788if delegateTo == "" {89fmt.Printf("Freezing %d SUN (%.6f TRX) to obtain %s resources for own account\n",90frozenBalance, sunToTrx(frozenBalance), resourceName)91} else {92fmt.Printf("Freezing %d SUN (%.6f TRX) to delegate %s resources to account %s\n",93frozenBalance, sunToTrx(frozenBalance), resourceName, delegateTo)94}9596fmt.Println("Creating freeze balance transaction...")9798tx, err := conn.FreezeBalance(99from, // From address100delegateTo, // Delegate to address (empty for self)101resource, // Resource type (BANDWIDTH or ENERGY)102frozenBalance, // Amount to freeze in SUN103)104105if err != nil {106fmt.Printf("Error creating freeze transaction: %v\n", err)107返回108}109110fmt.Println("Freeze transaction created successfully. Transaction details:")111jsonData, _ := json.MarshalIndent(tx, "", " ")112fmt.Println(string(jsonData))113114// Broadcast the transaction115fmt.Println("\nBroadcasting transaction to the TRON network...")116result, err := conn.Broadcast(tx.Transaction)117if err != nil {118fmt.Printf("Error broadcasting transaction: %v\n", err)119返回120}121122if !result.GetResult() {123fmt.Printf("Broadcast failed: %s\n", result.GetMessage())124返回125}126127fmt.Println("TRX frozen successfully! Result:")128resultJSON, _ := json.MarshalIndent(result, "", " ")129fmt.Println(string(resultJSON))130}