ExchangeWithdraw gRPC Method
매개변수
출처:
문자열
필수
로딩 중...
exchangeID
정수
필수
로딩 중...
tokenID
문자열
필수
로딩 중...
amountToken
정수
필수
로딩 중...
반품
거래
객체
로딩 중...
raw_data
객체
로딩 중...
ref_block_bytes
문자열
로딩 중...
ref_block_num
정수
로딩 중...
ref_block_hash
문자열
로딩 중...
expiration
정수
로딩 중...
auths
배열
로딩 중...
데이터
문자열
로딩 중...
contract
배열
로딩 중...
유형
문자열
로딩 중...
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
문자열
로딩 중...
참고
문자열
로딩 중...
rejected
부울
로딩 중...
extra
문자열
로딩 중...
energy_penalty
정수
로딩 중...
요청
1패키지 main23import (4"문맥"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 endpoint = "YOUR_ENDPOINT:50051"2021type auth struct {22token string23}2425func (a *auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {26return map[string]string{27"x-token": a.token,28}, nil29}3031func (a *auth) RequireTransportSecurity() bool {32return false33}3435func main() {3637opts := []grpc.DialOption{38grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),39grpc.WithPerRPCCredentials(&auth{token}),40}41conn := client.NewGrpcClient(endpoint)42if err := conn.Start(opts...); err != nil {43panic(err)44}45defer conn.Conn.Close()4647from := "TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g"48exchangeID := int64(123)4950fmt.Printf("Verifying exchange ID %d...\n", exchangeID)51exchange, err := conn.ExchangeByID(exchangeID)52if err != nil {53fmt.Printf("Error: The specified exchange does not exist: %v\n", err)54반환55}5657creatorAddress := string(exchange.CreatorAddress)58fmt.Printf("Exchange creator: %s\n", creatorAddress)59if creatorAddress != from {60fmt.Printf("Error: Only the exchange creator (%s) can withdraw liquidity\n", creatorAddress)61반환62}6364firstTokenID := string(exchange.FirstTokenId)65secondTokenID := string(exchange.SecondTokenId)66fmt.Printf("Exchange %d contains tokens: %s and %s\n",67exchangeID, firstTokenID, secondTokenID)68fmt.Printf("Current liquidity: %d %s and %d %s\n",69exchange.FirstTokenBalance, firstTokenID,70exchange.SecondTokenBalance, secondTokenID)7172tokenID := firstTokenID73amountToken := int64(1000000)7475if tokenID != firstTokenID && tokenID != secondTokenID {76fmt.Printf("Error: Token %s is not in exchange %d\n", tokenID, exchangeID)77반환78}7980var availableAmount int6481if tokenID == firstTokenID {82availableAmount = exchange.FirstTokenBalance83} else {84availableAmount = exchange.SecondTokenBalance85}8687if amountToken > availableAmount {88fmt.Printf("Error: Insufficient liquidity. Requested: %d, Available: %d\n",89amountToken, availableAmount)90반환91}9293var otherTokenAmount int6494if tokenID == firstTokenID {95otherTokenAmount = amountToken * exchange.SecondTokenBalance / exchange.FirstTokenBalance96fmt.Printf("Withdrawing %d %s will also withdraw approximately %d %s\n",97amountToken, firstTokenID, otherTokenAmount, secondTokenID)98} else {99otherTokenAmount = amountToken * exchange.FirstTokenBalance / exchange.SecondTokenBalance100fmt.Printf("Withdrawing %d %s will also withdraw approximately %d %s\n",101amountToken, secondTokenID, otherTokenAmount, firstTokenID)102}103104fmt.Println("Creating exchange withdrawal transaction...")105106tx, err := conn.ExchangeWithdraw(107from, // The address withdrawing liquidity (must be exchange creator)108exchangeID, // Exchange ID109tokenID, // Token ID to withdraw110amountToken, // Amount to withdraw111)112113if err != nil {114fmt.Printf("Error creating withdrawal transaction: %v\n", err)115반환116}117118fmt.Println("Withdrawal transaction created successfully. Transaction details:")119jsonData, _ := json.MarshalIndent(tx, "", " ")120fmt.Println(string(jsonData))121122// NOTE: In a production environment, the transaction should be signed here123fmt.Println("\nBroadcasting transaction to the TRON network...")124result, err := conn.Broadcast(tx.Transaction)125if err != nil {126fmt.Printf("Error broadcasting transaction: %v\n", err)127반환128}129130if !result.GetResult() {131fmt.Printf("Broadcast failed: %s\n", result.GetMessage())132반환133}134135fmt.Println("Liquidity withdrawal executed successfully! Result:")136resultJSON, _ := json.MarshalIndent(result, "", " ")137fmt.Println(string(resultJSON))138}
1패키지 main23import (4"문맥"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 endpoint = "YOUR_ENDPOINT:50051"2021type auth struct {22token string23}2425func (a *auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {26return map[string]string{27"x-token": a.token,28}, nil29}3031func (a *auth) RequireTransportSecurity() bool {32return false33}3435func main() {3637opts := []grpc.DialOption{38grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),39grpc.WithPerRPCCredentials(&auth{token}),40}41conn := client.NewGrpcClient(endpoint)42if err := conn.Start(opts...); err != nil {43panic(err)44}45defer conn.Conn.Close()4647from := "TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g"48exchangeID := int64(123)4950fmt.Printf("Verifying exchange ID %d...\n", exchangeID)51exchange, err := conn.ExchangeByID(exchangeID)52if err != nil {53fmt.Printf("Error: The specified exchange does not exist: %v\n", err)54반환55}5657creatorAddress := string(exchange.CreatorAddress)58fmt.Printf("Exchange creator: %s\n", creatorAddress)59if creatorAddress != from {60fmt.Printf("Error: Only the exchange creator (%s) can withdraw liquidity\n", creatorAddress)61반환62}6364firstTokenID := string(exchange.FirstTokenId)65secondTokenID := string(exchange.SecondTokenId)66fmt.Printf("Exchange %d contains tokens: %s and %s\n",67exchangeID, firstTokenID, secondTokenID)68fmt.Printf("Current liquidity: %d %s and %d %s\n",69exchange.FirstTokenBalance, firstTokenID,70exchange.SecondTokenBalance, secondTokenID)7172tokenID := firstTokenID73amountToken := int64(1000000)7475if tokenID != firstTokenID && tokenID != secondTokenID {76fmt.Printf("Error: Token %s is not in exchange %d\n", tokenID, exchangeID)77반환78}7980var availableAmount int6481if tokenID == firstTokenID {82availableAmount = exchange.FirstTokenBalance83} else {84availableAmount = exchange.SecondTokenBalance85}8687if amountToken > availableAmount {88fmt.Printf("Error: Insufficient liquidity. Requested: %d, Available: %d\n",89amountToken, availableAmount)90반환91}9293var otherTokenAmount int6494if tokenID == firstTokenID {95otherTokenAmount = amountToken * exchange.SecondTokenBalance / exchange.FirstTokenBalance96fmt.Printf("Withdrawing %d %s will also withdraw approximately %d %s\n",97amountToken, firstTokenID, otherTokenAmount, secondTokenID)98} else {99otherTokenAmount = amountToken * exchange.FirstTokenBalance / exchange.SecondTokenBalance100fmt.Printf("Withdrawing %d %s will also withdraw approximately %d %s\n",101amountToken, secondTokenID, otherTokenAmount, firstTokenID)102}103104fmt.Println("Creating exchange withdrawal transaction...")105106tx, err := conn.ExchangeWithdraw(107from, // The address withdrawing liquidity (must be exchange creator)108exchangeID, // Exchange ID109tokenID, // Token ID to withdraw110amountToken, // Amount to withdraw111)112113if err != nil {114fmt.Printf("Error creating withdrawal transaction: %v\n", err)115반환116}117118fmt.Println("Withdrawal transaction created successfully. Transaction details:")119jsonData, _ := json.MarshalIndent(tx, "", " ")120fmt.Println(string(jsonData))121122// NOTE: In a production environment, the transaction should be signed here123fmt.Println("\nBroadcasting transaction to the TRON network...")124result, err := conn.Broadcast(tx.Transaction)125if err != nil {126fmt.Printf("Error broadcasting transaction: %v\n", err)127반환128}129130if !result.GetResult() {131fmt.Printf("Broadcast failed: %s\n", result.GetMessage())132반환133}134135fmt.Println("Liquidity withdrawal executed successfully! Result:")136resultJSON, _ := json.MarshalIndent(result, "", " ")137fmt.Println(string(resultJSON))138}