-
Notifications
You must be signed in to change notification settings - Fork 42
/
example.go
87 lines (68 loc) · 2.05 KB
/
example.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"fmt"
"os"
"time"
"github.com/InjectiveLabs/sdk-go/client/common"
exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
cosmtypes "github.com/cosmos/cosmos-sdk/types"
rpchttp "github.com/tendermint/tendermint/rpc/client/http"
)
func main() {
// network := common.LoadNetwork("mainnet", "k8s")
network := common.LoadNetwork("testnet", "k8s")
tmRPC, err := rpchttp.New(network.TmEndpoint, "/websocket")
if err != nil {
fmt.Println(err)
}
senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
os.Getenv("HOME")+"/.injectived",
"injectived",
"file",
"inj-user",
"12345678",
"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
false,
)
if err != nil {
panic(err)
}
clientCtx, err := chainclient.NewClientContext(
network.ChainId,
senderAddress.String(),
cosmosKeyring,
)
if err != nil {
fmt.Println(err)
}
clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmRPC)
msg := &exchangetypes.MsgIncreasePositionMargin{
Sender: senderAddress.String(),
MarketId: "0x4ca0f92fc28be0c9761326016b5a1a2177dd6375558365116b5bdda9abc229ce",
SourceSubaccountId: "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000",
DestinationSubaccountId: "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000",
Amount: cosmtypes.MustNewDecFromStr("100000000"), //100 USDT
}
chainClient, err := chainclient.NewChainClient(
clientCtx,
network.ChainGrpcEndpoint,
common.OptionTLSCert(network.ChainTlsCert),
common.OptionGasPrices("500000000inj"),
)
if err != nil {
fmt.Println(err)
}
//AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg
err = chainClient.QueueBroadcastMsg(msg)
if err != nil {
fmt.Println(err)
}
time.Sleep(time.Second * 5)
gasFee, err := chainClient.GetGasFee()
if err != nil {
fmt.Println(err)
return
}
fmt.Println("gas fee:", gasFee, "INJ")
}