FreezeBalance gRPC Method
매개변수
출처:
문자열
필수
로딩 중...
delegateTo
문자열
필수
로딩 중...
resource
문자열
필수
로딩 중...
frozenBalance
정수
필수
로딩 중...
반품
거래
객체
로딩 중...
원시 데이터
객체
로딩 중...
ref_block_bytes
문자열
로딩 중...
ref_block_num
정수
로딩 중...
ref_block_hash
문자열
로딩 중...
만료
정수
로딩 중...
auths
배열
로딩 중...
데이터
문자열
로딩 중...
계약
배열
로딩 중...
유형
문자열
로딩 중...
매개변수
객체
로딩 중...
값
문자열
로딩 중...
type_url
문자열
로딩 중...
provider
문자열
로딩 중...
ContractName
문자열
로딩 중...
Permission_id
정수
로딩 중...
scripts
문자열
로딩 중...
타임스탬프
정수
로딩 중...
수수료 한도
정수
로딩 중...
서명
배열
로딩 중...
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
배열
로딩 중...
결과
객체
로딩 중...
결과
부울
로딩 중...
코드
문자열
로딩 중...
메시지
문자열
로딩 중...
에너지_사용량
정수
로딩 중...
로그
배열
로딩 중...
주소
문자열
로딩 중...
주제
배열
로딩 중...
데이터
문자열
로딩 중...
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 토큰 token = "YOUR_TOKEN"20var endpoint = "YOUR_ENDPOINT:50051"2122유형 auth struct {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패키지 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 토큰 token = "YOUR_TOKEN"20var endpoint = "YOUR_ENDPOINT:50051"2122유형 auth struct {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}