Skip to main content

ExchangeInject gRPC Method

Loading...

Updated on
May 13, 2025

ExchangeInject gRPC Method

Parameters

from
string
REQUIRED
Loading...
exchangeID
integer
REQUIRED
Loading...
tokenID
string
REQUIRED
Loading...
amountToken
integer
REQUIRED
Loading...

Returns

transaction
object
Loading...
raw_data
object
Loading...
ref_block_bytes
string
Loading...
ref_block_num
integer
Loading...
ref_block_hash
string
Loading...
expiration
integer
Loading...
auths
array
Loading...
data
string
Loading...
contract
array
Loading...
type
string
Loading...
parameter
object
Loading...
value
string
Loading...
type_url
string
Loading...
provider
string
Loading...
ContractName
string
Loading...
Permission_id
integer
Loading...
scripts
string
Loading...
timestamp
integer
Loading...
fee_limit
integer
Loading...
signature
array
Loading...
ret
array
Loading...
fee
integer
Loading...
ret
string
Loading...
contractRet
string
Loading...
assetIssueID
string
Loading...
withdraw_amount
integer
Loading...
unfreeze_amount
integer
Loading...
exchange_received_amount
integer
Loading...
exchange_inject_another_amount
integer
Loading...
exchange_withdraw_another_amount
integer
Loading...
exchange_id
integer
Loading...
shielded_transaction_fee
integer
Loading...
orderId
string
Loading...
orderDetails
array
Loading...
makerOrderId
string
Loading...
takerOrderId
string
Loading...
fillSellQuantity
integer
Loading...
fillBuyQuantity
integer
Loading...
withdraw_expire_amount
integer
Loading...
cancelUnfreezeV2Amount
object
Loading...
txid
string
Loading...
constant_result
array
Loading...
result
object
Loading...
result
boolean
Loading...
code
string
Loading...
message
string
Loading...
energy_used
integer
Loading...
logs
array
Loading...
address
string
Loading...
topics
array
Loading...
data
string
Loading...
internal_transactions
array
Loading...
hash
string
Loading...
caller_address
string
Loading...
transferTo_address
string
Loading...
callValueInfo
array
Loading...
callValue
integer
Loading...
tokenId
string
Loading...
note
string
Loading...
rejected
boolean
Loading...
extra
string
Loading...
energy_penalty
integer
Loading...
Request
1
package main
2
3
import (
4
"context"
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
)
12
13
// Quicknode endpoints consist of two crucial components: the endpoint name and the corresponding token
14
// For eg: QN Endpoint: https://docs-demo.tron-mainnet.quiknode.pro/abcde123456789
15
// endpoint will be: docs-demo.tron-mainnet.quiknode.pro:50051 {50051 is the port number for Tron gRPC}
16
// token will be : abcde123456789
17
18
var token = "YOUR_TOKEN"
19
var endpoint = "YOUR_ENDPOINT:50051"
20
21
type auth struct {
22
token string
23
}
24
25
func (a *auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
26
return map[string]string{
27
"x-token": a.token,
28
}, nil
29
}
30
31
func (a *auth) RequireTransportSecurity() bool {
32
return false
33
}
34
35
func main() {
36
37
opts := []grpc.DialOption{
38
grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})),
39
grpc.WithPerRPCCredentials(&auth{token}),
40
}
41
conn := client.NewGrpcClient(endpoint)
42
if err := conn.Start(opts...); err != nil {
43
panic(err)
44
}
45
defer conn.Conn.Close()
46
47
from := "TZ4UXDV5ZhNW7fb2AMSbgfAEZ7hWsnYS2g" // Address injecting the liquidity
48
exchangeID := int64(123) // ID of the exchange pair
49
tokenID := "1000001" // ID of the token to inject (first token in the pair)
50
amountToken := int64(10000000) // Amount of token to inject (in token's smallest unit)
51
52
fmt.Println("Injecting liquidity into exchange pair...")
53
54
tx, err := conn.ExchangeInject(
55
from, // The address injecting liquidity
56
exchangeID, // Exchange ID
57
tokenID, // Token ID
58
amountToken, // Token amount
59
)
60
61
if err != nil {
62
fmt.Printf("Error injecting liquidity: %v\n", err)
63
return
64
}
65
66
fmt.Println("Liquidity injection transaction created successfully. Transaction details:")
67
jsonData, _ := json.MarshalIndent(tx, "", " ")
68
fmt.Println(string(jsonData))
69
70
// NOTE: In a production environment, the transaction should be signed here
71
fmt.Println("\nBroadcasting transaction to the TRON network...")
72
result, err := conn.Broadcast(tx.Transaction)
73
if err != nil {
74
fmt.Printf("Error broadcasting transaction: %v\n", err)
75
return
76
}
77
78
if !result.GetResult() {
79
fmt.Printf("Broadcast failed: %s\n", result.GetMessage())
80
return
81
}
82
83
fmt.Println("Liquidity injected successfully! Result:")
84
resultJSON, _ := json.MarshalIndent(result, "", " ")
85
fmt.Println(string(resultJSON))
86
fmt.Println("\nNote: When injecting the first token, the second token will be automatically taken in the same ratio as the current exchange balance.")
87
fmt.Println("This ensures that the exchange rate remains the same after the injection.")
88
}
Don't have an account yet?
Create your Quicknode endpoint in seconds and start building
Get started for free