github.com/InjectiveLabs/sdk-go@v1.53.0/examples/chain/ibc/transfer/1_MsgTransfer/example.go (about) 1 package main 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "os" 7 8 "cosmossdk.io/math" 9 10 "github.com/InjectiveLabs/sdk-go/client" 11 "github.com/InjectiveLabs/sdk-go/client/common" 12 13 chainclient "github.com/InjectiveLabs/sdk-go/client/chain" 14 rpchttp "github.com/cometbft/cometbft/rpc/client/http" 15 sdktypes "github.com/cosmos/cosmos-sdk/types" 16 ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types" 17 ibccoretypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" 18 ) 19 20 func main() { 21 network := common.LoadNetwork("testnet", "lb") 22 tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") 23 if err != nil { 24 panic(err) 25 } 26 27 senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( 28 os.Getenv("HOME")+"/.injectived", 29 "injectived", 30 "file", 31 "inj-user", 32 "12345678", 33 "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided 34 false, 35 ) 36 37 if err != nil { 38 panic(err) 39 } 40 41 // initialize grpc client 42 clientCtx, err := chainclient.NewClientContext( 43 network.ChainId, 44 senderAddress.String(), 45 cosmosKeyring, 46 ) 47 if err != nil { 48 panic(err) 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 sourcePort := "transfer" 63 sourceChannel := "channel-126" 64 coin := sdktypes.Coin{ 65 Denom: "inj", Amount: math.NewInt(1000000000000000000), // 1 INJ 66 } 67 sender := senderAddress.String() 68 receiver := "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r" 69 timeoutHeight := ibccoretypes.Height{RevisionNumber: 10, RevisionHeight: 10} 70 71 msg := &ibctransfertypes.MsgTransfer{ 72 SourcePort: sourcePort, 73 SourceChannel: sourceChannel, 74 Token: coin, 75 Sender: sender, 76 Receiver: receiver, 77 TimeoutHeight: timeoutHeight, 78 } 79 80 // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg 81 response, err := chainClient.AsyncBroadcastMsg(msg) 82 83 if err != nil { 84 panic(err) 85 } 86 87 str, _ := json.MarshalIndent(response, "", " ") 88 fmt.Print(string(str)) 89 }