github.com/InjectiveLabs/sdk-go@v1.53.0/examples/chain/authz/query/1_Grants/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  	authztypes "github.com/cosmos/cosmos-sdk/x/authz"
    14  
    15  	"os"
    16  )
    17  
    18  func main() {
    19  	network := common.LoadNetwork("testnet", "lb")
    20  	tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket")
    21  	if err != nil {
    22  		panic(err)
    23  	}
    24  
    25  	senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring(
    26  		os.Getenv("HOME")+"/.injectived",
    27  		"injectived",
    28  		"file",
    29  		"inj-user",
    30  		"12345678",
    31  		"5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided
    32  		false,
    33  	)
    34  
    35  	if err != nil {
    36  		panic(err)
    37  	}
    38  
    39  	clientCtx, err := chainclient.NewClientContext(
    40  		network.ChainId,
    41  		senderAddress.String(),
    42  		cosmosKeyring,
    43  	)
    44  
    45  	if err != nil {
    46  		panic(err)
    47  	}
    48  
    49  	clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient)
    50  
    51  	chainClient, err := chainclient.NewChainClient(
    52  		clientCtx,
    53  		network,
    54  		common.OptionGasPrices(client.DefaultGasPriceWithDenom),
    55  	)
    56  
    57  	if err != nil {
    58  		panic(err)
    59  	}
    60  
    61  	granter := "inj14au322k9munkmx5wrchz9q30juf5wjgz2cfqku"
    62  	grantee := "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r"
    63  	msg_type_url := "/injective.exchange.v1beta1.MsgCreateSpotLimitOrder"
    64  
    65  	req := authztypes.QueryGrantsRequest{
    66  		Granter:    granter,
    67  		Grantee:    grantee,
    68  		MsgTypeUrl: msg_type_url,
    69  	}
    70  
    71  	ctx := context.Background()
    72  
    73  	res, err := chainClient.GetAuthzGrants(ctx, req)
    74  	if err != nil {
    75  		fmt.Println(err)
    76  	}
    77  
    78  	str, _ := json.MarshalIndent(res, "", " ")
    79  	fmt.Print(string(str))
    80  
    81  }