github.com/InjectiveLabs/sdk-go@v1.53.0/examples/chain/tokenfactory/2_MsgMint/example.go (about)

     1  package main
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"os"
     7  
     8  	"cosmossdk.io/math"
     9  
    10  	tokenfactorytypes "github.com/InjectiveLabs/sdk-go/chain/tokenfactory/types"
    11  	"github.com/InjectiveLabs/sdk-go/client"
    12  	chainclient "github.com/InjectiveLabs/sdk-go/client/chain"
    13  	"github.com/InjectiveLabs/sdk-go/client/common"
    14  	rpchttp "github.com/cometbft/cometbft/rpc/client/http"
    15  	sdktypes "github.com/cosmos/cosmos-sdk/types"
    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  		"f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3", // 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  	if err != nil {
    45  		fmt.Println(err)
    46  		return
    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  	message := new(tokenfactorytypes.MsgMint)
    61  	message.Sender = senderAddress.String()
    62  	message.Amount = sdktypes.Coin{
    63  		Denom:  "factory/inj1hkhdaj2a2clmq5jq6mspsggqs32vynpk228q3r/inj_test",
    64  		Amount: math.NewInt(1000000000),
    65  	}
    66  
    67  	// AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg
    68  	response, err := chainClient.AsyncBroadcastMsg(message)
    69  
    70  	if err != nil {
    71  		panic(err)
    72  	}
    73  
    74  	str, _ := json.MarshalIndent(response, "", " ")
    75  	fmt.Print(string(str))
    76  }