github.com/InjectiveLabs/sdk-go@v1.53.0/examples/chain/exchange/2_MsgWithdraw/example.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 "time" 7 8 "cosmossdk.io/math" 9 10 "github.com/InjectiveLabs/sdk-go/client" 11 "github.com/InjectiveLabs/sdk-go/client/common" 12 13 exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types" 14 chainclient "github.com/InjectiveLabs/sdk-go/client/chain" 15 rpchttp "github.com/cometbft/cometbft/rpc/client/http" 16 sdktypes "github.com/cosmos/cosmos-sdk/types" 17 ) 18 19 func main() { 20 network := common.LoadNetwork("testnet", "lb") 21 tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") 22 if err != nil { 23 panic(err) 24 } 25 26 senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( 27 os.Getenv("HOME")+"/.injectived", 28 "injectived", 29 "file", 30 "inj-user", 31 "12345678", 32 "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided 33 false, 34 ) 35 36 if err != nil { 37 panic(err) 38 } 39 40 clientCtx, err := chainclient.NewClientContext( 41 network.ChainId, 42 senderAddress.String(), 43 cosmosKeyring, 44 ) 45 46 if err != nil { 47 panic(err) 48 } 49 50 clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) 51 52 chainClient, err := chainclient.NewChainClient( 53 clientCtx, 54 network, 55 common.OptionGasPrices(client.DefaultGasPriceWithDenom), 56 ) 57 58 if err != nil { 59 panic(err) 60 } 61 62 msg := &exchangetypes.MsgWithdraw{ 63 Sender: senderAddress.String(), 64 SubaccountId: "0xaf79152ac5df276d9a8e1e2e22822f9713474902000000000000000000000000", 65 Amount: sdktypes.Coin{ 66 Denom: "inj", Amount: math.NewInt(1000000000000000000), // 1 INJ 67 }, 68 } 69 70 // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg 71 err = chainClient.QueueBroadcastMsg(msg) 72 73 if err != nil { 74 fmt.Println(err) 75 } 76 77 time.Sleep(time.Second * 5) 78 79 gasFee, err := chainClient.GetGasFee() 80 81 if err != nil { 82 fmt.Println(err) 83 return 84 } 85 86 fmt.Println("gas fee:", gasFee, "INJ") 87 }