github.com/InjectiveLabs/sdk-go@v1.53.0/examples/chain/exchange/27_MsgActivateStakeGrant/example.go (about)

     1  package main
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"os"
     7  
     8  	"github.com/InjectiveLabs/sdk-go/client"
     9  
    10  	"github.com/InjectiveLabs/sdk-go/client/common"
    11  
    12  	exchangetypes "github.com/InjectiveLabs/sdk-go/chain/exchange/types"
    13  	chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
    14  	rpchttp "github.com/cometbft/cometbft/rpc/client/http"
    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  	msg := &exchangetypes.MsgActivateStakeGrant{
    61  		Sender:  senderAddress.String(),
    62  		Granter: "inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r",
    63  	}
    64  
    65  	// AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg
    66  	response, err := chainClient.AsyncBroadcastMsg(msg)
    67  
    68  	if err != nil {
    69  		panic(err)
    70  	}
    71  
    72  	str, _ := json.MarshalIndent(response, "", " ")
    73  	fmt.Print(string(str))
    74  }