ExchangeWithdraw gRPC Method
参数
来自
字符串
必填
正在加载...
exchangeID
整数
必填
正在加载...
tokenID
字符串
必填
正在加载...
amountToken
整数
必填
正在加载...
退货
交易
对象
正在加载...
原始数据
对象
正在加载...
ref_block_bytes
字符串
正在加载...
ref_block_num
整数
正在加载...
ref_block_hash
字符串
正在加载...
到期
整数
正在加载...
auths
数组
正在加载...
数据
字符串
正在加载...
合同
数组
正在加载...
类型
字符串
正在加载...
参数
对象
正在加载...
值
字符串
正在加载...
type_url
字符串
正在加载...
提供商
字符串
正在加载...
合同名称
字符串
正在加载...
Permission_id
整数
正在加载...
脚本
字符串
正在加载...
时间戳
整数
正在加载...
fee_limit
整数
正在加载...
签名
数组
正在加载...
ret
数组
正在加载...
费用
整数
正在加载...
ret
字符串
正在加载...
contractRet
字符串
正在加载...
资产问题ID
字符串
正在加载...
取款金额
整数
正在加载...
解冻金额
整数
正在加载...
exchange_received_amount
整数
正在加载...
exchange_inject_another_amount
整数
正在加载...
exchange_withdraw_another_amount
整数
正在加载...
exchange_id
整数
正在加载...
受保护的交易费
整数
正在加载...
订单编号
字符串
正在加载...
订单详情
数组
正在加载...
makerOrderId
字符串
正在加载...
takerOrderId
字符串
正在加载...
fillSellQuantity
整数
正在加载...
fillBuyQuantity
整数
正在加载...
取款_到期金额
整数
正在加载...
cancelUnfreezeV2Amount
对象
正在加载...
txid
字符串
正在加载...
常量结果
数组
正在加载...
结果
对象
正在加载...
结果
布尔型
正在加载...
代码
字符串
正在加载...
消息
字符串
正在加载...
energy_used
整数
正在加载...
日志
数组
正在加载...
地址
字符串
正在加载...
主题
数组
正在加载...
数据
字符串
正在加载...
内部交易
数组
正在加载...
哈希
字符串
正在加载...
caller_address
字符串
正在加载...
transferTo_address
字符串
正在加载...
callValueInfo
数组
正在加载...
callValue
整数
正在加载...
tokenId
字符串
正在加载...
注
字符串
正在加载...
被拒绝
布尔型
正在加载...
额外
字符串
正在加载...
能量消耗
整数
正在加载...
请求
1包 main23导入 (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 端点 = "YOUR_ENDPOINT:50051"2021类型 auth 结构体 {22token string23}2425func (a *auth) GetRequestMetadata(ctx 上下文.上下文, uri ...字符串) (map[字符串]字符串, 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包 main23导入 (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 端点 = "YOUR_ENDPOINT:50051"2021类型 auth 结构体 {22token string23}2425func (a *auth) GetRequestMetadata(ctx 上下文.上下文, uri ...字符串) (map[字符串]字符串, 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}