Skip to content
Cosmopediaby Unity Nodes
DiscussionsCosmos-SDKHow to override DefaultGenesis?Forum ↗

How to override DefaultGenesis?

Cosmos-SDK3 posts764 viewsLast activity Sep 2020
YO
youngjoon-leeOP
Sep 2020

Hi all,

I’ve been implementing a blockchain on the top of the Cosmos SDK.

Everything works well, but I’d like to override DefaultGenesis functions of some modules (such as ‘staking’).
For example, I want to use a custom value of MaxValidators, instead of the DefaultMaxValidators defined in the x/staking/types/params.go.

But, it seems there is no way to override the value.
In the genutilcli.InitCmd(), the DefaultGenesis() is used.

Please suggest any idea how to override default genesis params of the existing modules.
Thank you.

Youngjoon

JH
jhernandezb
Sep 2020

Which version of the sdk are you using?

We made a wrapper round the init command so after it generates the genesis it reads the file again and set our custom default params as bond_denom, and others.

github.com

public-awesome/stakebird/blob/ae80ee9bd30c0958d5f57a1e84d6650ddbfd864f/cmd/staked/init.go#L95

  1. if err != nil {
  2. return appState, err
  3. }
  4. mintGenState.Params.MintDenom = stakeDenom
  5. appState[mint.ModuleName] = cdc.MustMarshalJSON(mintGenState)
  6. }
  7. return appState, nil
  8. }
  9. // InitCmd wraps the genutil.InitCmd to inject specific settings for rocket chain
  10. func InitCmd(ctx *server.Context, cdc codec.JSONMarshaler, mbm module.BasicManager,
  11. defaultNodeHome string) *cobra.Command {
  12. init := genutilcli.InitCmd(ctx, cdc, app.ModuleBasics, app.DefaultNodeHome)
  13. init.PostRunE = func(cmd *cobra.Command, args []string) error {
  14. config := ctx.Config
  15. config.SetRoot(viper.GetString(cli.HomeFlag))
  16. genFile := config.GenesisFile()
  17. genDoc := &types.GenesisDoc{}
YO
youngjoon-lee
Sep 2020

Awesome! Thank you. I’m using v0.37.14. It seems it has the PostRunE.

← Back to Discussions