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