github.com/InjectiveLabs/sdk-go@v1.53.0/examples/chain/ibc/connection/query/1_Connection/example.go (about) 1 package main 2 3 import ( 4 "context" 5 "encoding/json" 6 "fmt" 7 8 "github.com/InjectiveLabs/sdk-go/client" 9 10 chainclient "github.com/InjectiveLabs/sdk-go/client/chain" 11 "github.com/InjectiveLabs/sdk-go/client/common" 12 rpchttp "github.com/cometbft/cometbft/rpc/client/http" 13 14 "os" 15 ) 16 17 func main() { 18 network := common.LoadNetwork("testnet", "lb") 19 tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") 20 if err != nil { 21 panic(err) 22 } 23 24 senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( 25 os.Getenv("HOME")+"/.injectived", 26 "injectived", 27 "file", 28 "inj-user", 29 "12345678", 30 "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided 31 false, 32 ) 33 34 if err != nil { 35 panic(err) 36 } 37 38 clientCtx, err := chainclient.NewClientContext( 39 network.ChainId, 40 senderAddress.String(), 41 cosmosKeyring, 42 ) 43 44 if err != nil { 45 panic(err) 46 } 47 48 clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) 49 50 chainClient, err := chainclient.NewChainClient( 51 clientCtx, 52 network, 53 common.OptionGasPrices(client.DefaultGasPriceWithDenom), 54 ) 55 56 if err != nil { 57 panic(err) 58 } 59 60 connectionId := "connection-0" 61 ctx := context.Background() 62 63 res, err := chainClient.FetchIBCConnection(ctx, connectionId) 64 if err != nil { 65 fmt.Println(err) 66 } 67 68 str, _ := json.MarshalIndent(res, "", " ") 69 fmt.Print(string(str)) 70 71 }