github.com/InjectiveLabs/sdk-go@v1.53.0/examples/chain/distribution/4_FundCommunityPool/example.go (about) 1 package main 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "os" 7 8 "cosmossdk.io/math" 9 10 "github.com/cosmos/cosmos-sdk/types" 11 distriutiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" 12 13 "github.com/InjectiveLabs/sdk-go/client" 14 chainclient "github.com/InjectiveLabs/sdk-go/client/chain" 15 "github.com/InjectiveLabs/sdk-go/client/common" 16 rpchttp "github.com/cometbft/cometbft/rpc/client/http" 17 ) 18 19 func main() { 20 network := common.LoadNetwork("testnet", "lb") 21 tmClient, err := rpchttp.New(network.TmEndpoint, "/websocket") 22 if err != nil { 23 panic(err) 24 } 25 26 senderAddress, cosmosKeyring, err := chainclient.InitCosmosKeyring( 27 os.Getenv("HOME")+"/.injectived", 28 "injectived", 29 "file", 30 "inj-user", 31 "12345678", 32 "5d386fbdbf11f1141010f81a46b40f94887367562bd33b452bbaa6ce1cd1381e", // keyring will be used if pk not provided 33 false, 34 ) 35 36 if err != nil { 37 panic(err) 38 } 39 40 clientCtx, err := chainclient.NewClientContext( 41 network.ChainId, 42 senderAddress.String(), 43 cosmosKeyring, 44 ) 45 46 if err != nil { 47 panic(err) 48 } 49 50 clientCtx = clientCtx.WithNodeURI(network.TmEndpoint).WithClient(tmClient) 51 52 chainClient, err := chainclient.NewChainClient( 53 clientCtx, 54 network, 55 common.OptionGasPrices(client.DefaultGasPriceWithDenom), 56 ) 57 58 if err != nil { 59 panic(err) 60 } 61 62 amount := types.NewCoin("inj", math.NewInt(1)) 63 64 msg := &distriutiontypes.MsgFundCommunityPool{ 65 Amount: []types.Coin{amount}, 66 Depositor: senderAddress.String(), 67 } 68 69 // AsyncBroadcastMsg, SyncBroadcastMsg, QueueBroadcastMsg 70 response, err := chainClient.AsyncBroadcastMsg(msg) 71 72 if err != nil { 73 panic(err) 74 } 75 76 str, _ := json.MarshalIndent(response, "", " ") 77 fmt.Print(string(str)) 78 }