Cosmos-- 三.教程 -- 15.编译并运行程序

cosmos主网即将上线,对文档做了大量更新。特地翻译了一下,方便小伙伴们阅览, 之后会持续更新

第三章教程:

  1. 开始
  2. 程序目标
  3. 开始编写你的程序
  4. Keeper
  5. Msg和Handler
  6. SetName
  7. BuyName
  8. Querier
  9. Codec文件
  10. Nameservice模块的CLI
  11. nameservice模块的REST接口
  12. 引入你的模块并完成程序
  13. Entrypoint
  14. 编译你的程序
  15. 编译并运行程序
  16. 运行REST路由

编译并运行程序

编译nameservice应用

如果要在此仓库中编译nameservice应用程序以查看功能,首先需要安装dep

注意注意:你的应用程序需要导入你刚编写的代码。这里导入路径设置为此存储库(github.com/cosmos/sdk-application-tutorial)。如果您是在自己的仓库中进行的前面的操作,则需要更改导入路径(github.com/{.Username}/{.Project.Repo})。

# Initialize dep and install dependencies
make get_tools && make get_vendor_deps

# Install the app into your $GOBIN
make install

# Now you should be able to run the following commands:
nsd help
nscli help

运行活跃的网络并使用操作命令

要初始化配置和应用程序的genesis.json文件和及一个用于交易的帐户,请先运行:

注意:在下面的命令中,使用终端来提取地址。你也可以只是输入创建密钥时保存的原始字符串,如下所示。这些命令需要在你的机器上安装jq

注意:如果你之前已经运行过该教程,则可以从头开始使用nsd unsafe-reset-all或删除home文件夹下的两个执行程序的数据及配置文件夹rm -rf~ / .ns *

# Initialize configuration files and genesis file
nsd init --chain-id testchain

# Copy the `Address` output here and save it for later use
nscli keys add jack

# Copy the `Address` output here and save it for later use
nscli keys add alice

# Add both accounts, with coins to the genesis file
nsd add-genesis-account $(nscli keys show jack -a) 1000mycoin,1000jackcoin
nsd add-genesis-account $(nscli keys show alice -a) 1000mycoin,1000alicecoin

# Configure your CLI to eliminate need for chain-id flag
nscli config chain-id testchain
nscli config output json
nscli config indent true
nscli config trust-node true

你现在可以通过调用nsd start来启动nsd。你将看到日志开始不停输出,表示正在生成的区块,这将花费几秒钟。

打开另一个终端,对刚刚创建的网络运行命令:

# First check the accounts to ensure they have funds
nscli query account $(nscli keys show jack -a) \
    --chain-id testchain
nscli query account $(nscli keys show alice -a) \
    --chain-id testchain

# Buy your first name using your coins from the genesis file
nscli tx nameservice buy-name jack.id 5mycoin \
    --from     jack \
    --chain-id testchain

# Set the value for the name you just bought
nscli tx nameservice set-name jack.id 8.8.8.8 \
    --from     jack \
    --chain-id testchain

# Try out a resolve query against the name you registered
nscli query nameservice resolve jack.id --chain-id testchain
# > 8.8.8.8

# Try out a whois query against the name you just registered
nscli query nameservice whois jack.id --chain-id testchain
# > {"value":"8.8.8.8","owner":"cosmos1l7k5tdt2qam0zecxrx78yuw447ga54dsmtpk2s","price":[{"denom":"mycoin","amount":"5"}]}

# Alice buys name from jack
nscli tx nameservice buy-name jack.id 10mycoin \
    --from     alice \
    --chain-id testchain

你可能感兴趣的:(Cosmos-- 三.教程 -- 15.编译并运行程序)