README
¶
Faucet Module
This module will enable mint function. Every address can mint 100(bonded tokens) in every 24 hours by sending a mint message.
For security consideration, you can add this module to your project as you want, but this module would NOT be active by default. unless you active it manually by adding "-tags faucet"
when you build or install.
这个水龙头模块提供铸币功能,每一个地址都可以发送mint消息为自己铸造一定数量的币,时间间隔为24小时。
出于安全考虑,你可以随意将本模块加入到你的项目代码中,但是默认是不会生效的,除非在编译的时候加上-tags faucet
手动激活这个模块
Developer Tutorial
Step 1: Import to your app.go
import (
"github.com/cosmos/modules/incubator/faucet"
)
Step 2: Declare faucet module and permission in app.go
ModuleBasics = module.NewBasicManager(
..., // the official basic modules
faucet.AppModule{}, // add faucet module
)
// account permissions
maccPerms = map[string][]string{
staking.BondedPoolName: {supply.Burner, supply.Staking},
staking.NotBondedPoolName: {supply.Burner, supply.Staking},
faucet.ModuleName: {supply.Minter}, // add permissions for faucet
}
type nameServiceApp struct {
*bam.BaseApp
cdc *codec.Codec
// Other Keepers ... ...
// Declare faucet keeper here
faucetKeeper faucet.Keeper
// Module Manager
mm *module.Manager
// simulation manager
sm *module.SimulationManager
}
Step 3: Initialize faucet keeper and faucet module in func NewNameserviceApp() in app.go
keys := sdk.NewKVStoreKeys(
bam.MainStoreKey,
auth.StoreKey,
staking.StoreKey,
supply.StoreKey,
distr.StoreKey,
slashing.StoreKey,
params.StoreKey,
faucet.StoreKey) // add faucet key
... // some stuff in between
app.faucetKeeper = faucet.NewKeeper(
app.supplyKeeper,
app.stakingKeeper,
10 * 1000000, // amount for mint
24 * time.Hour, // rate limit by time
keys[faucet.StoreKey],
app.cdc,)
app.mm = module.NewManager(
..., // other modules
faucet.NewAppModule(app.faucetKeeper), // add faucet module
)
Step 4: Enable faucet in Makefile
installWithFaucet: go.sum
go install -mod=readonly $(BUILD_FLAGS) -tags faucet ./cmd/nsd
go install -mod=readonly $(BUILD_FLAGS) -tags faucet ./cmd/nscli
Step 5: Build your app
make installWithFaucet
Step 6: Initialize faucet and publish to blockchain.
Create an account with default password "12345678", and publish it to blockchain, therefore others are able to load this account to mint coins.
nscli tx faucet publish --from faucet --chain-id test
{
"chain_id": "test",
"account_number": "3",
"sequence": "2",
"fee": {
"amount": [],
"gas": "200000"
},
"msgs": [
{
"type": "faucet/FaucetKey",
"value": {
"Sender": "cosmos14pkakt8apdm0e49tzp6gy3lwe8u04ajched5qm",
"Armor": "-----BEGIN TENDERMINT KEY INFO-----\ntype: Info\nversion: 0.0.0\n\nZA2tFT0KBHBpbmcSJuta6YchA8yOxBXjUwLzUeBxeECHpLU2GwILK/7OVbMF6uiX\nl/PNGiXhsPebIP3XBLEM0VlX6/whk4LtlqqvYLOduCLGh1yS0OE4SQFWIglzZWNw\nMjU2azE=\n=WAST\n-----END TENDERMINT KEY INFO-----"
}
}
],
"memo": ""
}
Congratulations, you are ready to mint
Usage / 用法
1: Initialize faucet
nscli tx faucet init --chain-id test
The faucet has been loaded successfully.
2: Mint coins.
iMac:~ liangping$ nscli tx faucet mintfor cosmos17l3gw079cn5x9d3pqa0jk0xhrw2mt358xvw555 --from faucet --chain-id test -y
{
"height": "0",
"txhash": "40F2AB8AD75B39532622302A71CB84523847D2E43D36B185E0CE65CE60208AB0",
"raw_log": "[]"
}
iMac:~ liangping$ nscli query account cosmos17l3gw079cn5x9d3pqa0jk0xhrw2mt358xvw555 --chain-id test
{
"type": "cosmos-sdk/Account",
"value": {
"address": "cosmos17l3gw079cn5x9d3pqa0jk0xhrw2mt358xvw555",
"coins": [
{
"denom": "stake",
"amount": "100000000"
}
],
"public_key": "",
"account_number": 7,
"sequence": 0
}
}
Also, you are able to mint for yourself if your address has actived/existed on blockchain.
$ nscli tx faucet mint --from YOUR_OTHER_ACCOUNT --chain-id test -y
{
"height": "0",
"txhash": "40F2AB8AD75B39532622302A71CB84523847D2E43D36B185E0CE65CE60208AB0",
"raw_log": "[]"
}
Compatible Version
cosmos-sdk v0.38.0 or above
Contact Us
Author: liangping from Ping.pub
If you like this module, welcome to delegate to Ping.pub on Cosmoshub, IRISHub, KAVA.
Documentation
¶
Index ¶
- Constants
- Variables
- func NewHandler(k keeper.Keeper) sdk.Handler
- type AppModule
- func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock)
- func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate
- func (am AppModule) ExportGenesis(_ sdk.Context, cdc codec.JSONMarshaler) json.RawMessage
- func (am AppModule) InitGenesis(_ sdk.Context, _ codec.JSONMarshaler, _ json.RawMessage) []abci.ValidatorUpdate
- func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier
- func (AppModule) QuerierRoute() string
- func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry)
- func (am AppModule) RegisterServices(cfg module.Configurator)
- func (am AppModule) Route() sdk.Route
- type AppModuleBasic
- func (AppModuleBasic) DefaultGenesis(_ codec.JSONMarshaler) json.RawMessage
- func (AppModuleBasic) GetQueryCmd() *cobra.Command
- func (AppModuleBasic) GetTxCmd() *cobra.Command
- func (AppModuleBasic) Name() string
- func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux)
- func (AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry)
- func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino)
- func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, r *mux.Router)
- func (AppModuleBasic) ValidateGenesis(_ codec.JSONMarshaler, config client.TxEncodingConfig, _ json.RawMessage) error
- type DenomConfig
- type Keeper
Constants ¶
const ( ModuleName = types.ModuleName RouterKey = types.RouterKey StoreKey = types.StoreKey )
exported consts
const ( MAINNET = "mainnet" TESTNET = "testnet" )
faucet contants
Variables ¶
var ( NewKeeper = keeper.NewKeeper NewMsgMint = types.NewMsgMint )
exported vars
Functions ¶
Types ¶
type AppModule ¶
type AppModule struct { AppModuleBasic // contains filtered or unexported fields }
AppModule implements the sdk.AppModule interface
func NewAppModule ¶
NewAppModule creates a new AppModule object
func (AppModule) BeginBlock ¶
func (am AppModule) BeginBlock(ctx sdk.Context, req abci.RequestBeginBlock)
BeginBlock returns the begin blocker for the curating module.
func (AppModule) EndBlock ¶
func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate
EndBlock does nothing
func (AppModule) ExportGenesis ¶
func (am AppModule) ExportGenesis(_ sdk.Context, cdc codec.JSONMarshaler) json.RawMessage
ExportGenesis is always empty, as InitGenesis does nothing either
func (AppModule) InitGenesis ¶
func (am AppModule) InitGenesis(_ sdk.Context, _ codec.JSONMarshaler, _ json.RawMessage) []abci.ValidatorUpdate
InitGenesis is ignored, no sense in serializing future upgrades
func (AppModule) LegacyQuerierHandler ¶
func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier
LegacyQuerierHandler registers a query handler to respond to the module-specific queries
func (AppModule) QuerierRoute ¶
QuerierRoute returns the route we respond to for abci queries
func (AppModule) RegisterInvariants ¶
func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry)
RegisterInvariants does nothing, there are no invariants to enforce
func (AppModule) RegisterServices ¶
func (am AppModule) RegisterServices(cfg module.Configurator)
RegisterServices registers module services.
type AppModuleBasic ¶
type AppModuleBasic struct{}
AppModuleBasic implements the sdk.AppModuleBasic interface
func (AppModuleBasic) DefaultGenesis ¶
func (AppModuleBasic) DefaultGenesis(_ codec.JSONMarshaler) json.RawMessage
DefaultGenesis is an empty object
func (AppModuleBasic) GetQueryCmd ¶
func (AppModuleBasic) GetQueryCmd() *cobra.Command
GetQueryCmd returns the cli query commands for this module
func (AppModuleBasic) GetTxCmd ¶
func (AppModuleBasic) GetTxCmd() *cobra.Command
GetTxCmd returns the transaction commands for this module
func (AppModuleBasic) RegisterGRPCGatewayRoutes ¶
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux)
RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the upgrade module.
func (AppModuleBasic) RegisterInterfaces ¶
func (AppModuleBasic) RegisterInterfaces(registry cdctypes.InterfaceRegistry)
RegisterInterfaces registers the module's interface types
func (AppModuleBasic) RegisterLegacyAminoCodec ¶
func (AppModuleBasic) RegisterLegacyAminoCodec(cdc *codec.LegacyAmino)
RegisterLegacyAminoCodec registers the upgrade types on the LegacyAmino codec
func (AppModuleBasic) RegisterRESTRoutes ¶
func (AppModuleBasic) RegisterRESTRoutes(clientCtx client.Context, r *mux.Router)
RegisterRESTRoutes registers all REST query handlers
func (AppModuleBasic) ValidateGenesis ¶
func (AppModuleBasic) ValidateGenesis(_ codec.JSONMarshaler, config client.TxEncodingConfig, _ json.RawMessage) error
ValidateGenesis is always successful, as we ignore the value