使用硬件钱包来存储你的密钥,可以显著提升加密资产的安全性。Ledger 设备充当助记词种子和私钥的隔离环境,交易签名过程也在设备内部完成。任何私密信息都不会离开 Ledger 设备。下面是一份简短教程,介绍如何将 Cosmos Ledger 应用与 Gaia CLI 或 Keplr 钱包扩展配合使用。 Ledger 设备的核心是一组助记词种子短语,用于生成私钥。该短语会在你初始化 Ledger 时生成。这个助记词与 Cosmos 兼容,可用于初始化新账户。
不要丢失这 24 个单词,也不要与任何人分享。为了防止资金被盗或丢失,最佳做法是将助记词备份多份,并分别保存在安全可靠的地方。如果有人获得了你的助记词访问权限,他们将完全控制与之关联的账户。

安装 Cosmos Ledger 应用

在使用 Keplr 或 gaiad 之前,你必须先在 Ledger 设备上安装 Cosmos 应用。操作步骤如下:
  1. 在你的电脑上安装 Ledger Live。
  2. 使用 Ledger Live,将你的 Ledger Nano S 固件更新到最新版本。
  3. 在 Ledger Live 应用中,进入 Manager 菜单。 Ledger Live 管理界面
  4. 连接你的 Ledger Nano 设备,并在设备上允许 Ledger Manager 访问。
  5. 在 Ledger Live 应用中搜索 Cosmos。 搜索 Cosmos 应用
  6. 点击 Install 安装 Cosmos 应用。
如果搜索时看不到 Cosmos 应用,你可能需要启用 Ledger Live 应用“实验性功能”标签页中的 Developer Mode。
启用开发者模式

Keplr + Ledger Nano

注意:在阅读本节之前,你需要先在 Ledger Nano 上安装 Cosmos 应用
  1. 将 Ledger 设备连接到电脑,使用 PIN 解锁,并打开 Cosmos 应用。
  2. 安装 Keplr 浏览器扩展。
  3. 点击 Keplr 扩展图标,选择 Import Ledger,然后设置账户名称和密码。
  4. 确保 Ledger 设备已解锁且已打开 Cosmos 应用,然后按照 Keplr 弹窗中的说明继续操作。
这样就完成了。现在你可以将 Keplr 与 Ledger Nano S 一起使用。你也可以使用 Keplr Web 应用 更详细地查看你的 Cosmos 账户概览。 注意:每次发送交易时,你都需要在 Ledger 设备上进行确认。Keplr 界面会提示你完成该操作

(可选)确认你的地址

你可以直接在 Ledger Nano 设备上再次确认 Keplr 显示的地址是否正确。操作如下:
  1. 将 Ledger 连接到电脑,并在设备上打开 Cosmos 应用。
  2. 打开 Cosmos 应用后,点击右侧按钮进入 Show Address 选项。
  3. 同时按下两个按钮,然后选择 Account 0 和 Index 0。
现在你应该会看到与 Keplr 扩展中显示相同的地址。 如果你想进一步了解如何使用 Keplr,建议查看它们的文档。 你也可以查看 Ledger 支持页面 了解更多细节。

Gaia CLI + Ledger Nano

注意:在阅读本节之前,你需要先在 Ledger Nano 上安装 Cosmos 应用 在 Cosmos Hub 网络中,用于生成地址和交易的工具是 gaiad。以下是入门方法。如果你不熟悉 CLI 工具,请下滑并改为按照 Keplr 钱包的说明操作。

开始之前

使用以下命令验证 gaiad 是否已正确安装
gaiad version --long

➜ cosmos-sdk: 0.34.3
git commit: 67ab0b1e1d1e5b898c8cbdede35ad5196dba01b2
vendor hash: 0341b356ad7168074391ca7507f40b050e667722
build tags: netgo ledger
go version go1.11.5 darwin/amd64

添加你的 Ledger 密钥

  • 连接并解锁你的 Ledger 设备。
  • 在 Ledger 上打开 Cosmos 应用。
  • 在 gaiad 中基于 Ledger 密钥创建账户。
请务必将 keyName 参数改成有实际意义的名称。ledger 标志会告诉 gaiad 使用你的 Ledger 来初始化该账户。
gaiad keys add <keyName> --ledger

➜ NAME: TYPE: ADDRESS:     PUBKEY:
<keyName> ledger cosmos1... cosmospub1...
Cosmos 使用 HD Wallets。这意味着你可以使用同一个 Ledger 种子配置多个账户。若要基于 Ledger 设备再创建一个账户,请运行以下命令(将整数 i 改为某个 >= 0 的值,以选择 HD 派生使用的账户):
gaiad keys add <secondKeyName> --ledger --account <i>

确认你的地址

运行以下命令以在设备上显示你的地址。请使用你为 Ledger 密钥设置的 keyName。-d 标志在 1.5.0 及更高版本中受支持。
gaiad keys show <keyName> -d
确认设备上显示的地址与添加密钥时显示的地址一致。

连接到全节点

接下来,你需要为 gaiad 配置一个 Cosmos 全节点的 URL,以及对应的 chain_id。在本例中,我们连接到 Chorus One 在 cosmoshub-2 链上运营的公共负载均衡全节点。但你也可以将 gaiad 指向任何 Cosmos 全节点。请确保 chain-id 与该全节点所在链保持一致。
gaiad config node https://cosmos.chorus.one:26657
gaiad config chain_id cosmoshub-2
你可以通过如下查询测试连接:
gaiad query staking validators
如果你想在本地运行自己的全节点,可在这里阅读更多内容。

签署交易

现在你已经可以开始签名并发送交易了。使用 tx send 命令通过 gaiad 发送交易。
gaiad tx bank send --help # 查看所有可用选项。
在运行这些命令之前,请务必先使用 PIN 解锁设备并打开 Cosmos 应用
使用你为 Ledger 密钥设置的 keyName,gaia 将连接到 Cosmos Ledger 应用并对交易进行签名。
gaiad tx bank send <keyName> <destinationAddress> <amount><denomination>
当出现 confirm transaction before signing 提示时,输入 Y。 接下来,系统会提示你在 Ledger 设备上检查并批准这笔交易。请务必检查屏幕上显示的交易 JSON。你可以逐项滚动查看每个字段和每条消息。继续向下阅读可以了解标准交易对象中的各个数据字段含义。 现在,你已经可以开始在网络上发送交易了。

接收资金

如果你希望资金转入 Ledger 设备上的 Cosmos 账户,可以使用以下命令获取 Ledger 账户地址(即 TYPE ledger 的那些账户):
gaiad keys list

➜ NAME: TYPE: ADDRESS:     PUBKEY:
<keyName> ledger cosmos1... cosmospub1...

更多文档

不确定 gaiad 能做什么?直接运行不带参数的命令,即可输出其支持命令的说明文档。
gaiad 的帮助命令是分层嵌套的。因此,$ gaiad 会输出顶层命令(status、config、query 和 tx)的文档。你可以继续为子命令添加 help,以查看更深层级的文档。例如,打印 query 命令的帮助:
gaiad query --help
或者打印 tx(交易)命令的帮助:
gaiad tx --help

Cosmos 标准交易

Cosmos 中的交易会嵌入 Cosmos SDK 的标准交易类型。Ledger 设备会在签名前显示该对象的序列化 JSON 表示,供你检查。以下是各字段及其含义:
  • chain-id:你要广播该交易的链,例如 gaia-13003 测试网,或 cosmoshub-2:主网。
  • account_number:发送账户的全局 ID,在该账户第一次收到资金时分配。
  • sequence:该账户的 nonce,每发送一笔交易递增一次。
  • fee:描述交易手续费的 JSON 对象,包括 gas 数量和币种面额。
  • memo:可选文本字段,可用于以多种方式标记交易。
  • msgs_<index>/<field>:交易中包含的消息数组。双击可继续查看 JSON 中嵌套字段的详细内容。

支持

如需进一步支持,建议先查看我们论坛中的相关帖子。 也欢迎在我们的 Telegram 频道 中联系并寻求帮助。 以下是来自优秀 Cosmos 社区的一些相关且实用的教程:
Using a hardware wallet to store your keys greatly improves the security of your crypto assets. The Ledger device acts as an enclave of the seed and private keys, and the process of signing transactions takes place within it. No private information ever leaves the Ledger device. The following is a short tutorial on using the Cosmos Ledger app with the Gaia CLI or the Keplr wallet extension. At the core of a Ledger device there is a mnemonic seed phrase that is used to generate private keys. This phrase is generated when you initialize your Ledger. The mnemonic is compatible with Cosmos and can be used to seed new accounts.
Do not lose or share your 24 words with anyone. To prevent theft or loss of funds, it is best to keep multiple copies of your mnemonic stored in safe, secure places. If someone is able to gain access to your mnemonic, they will fully control the accounts associated with them.

Install the Cosmos Ledger application

Installing the Cosmos application on your ledger device is required before you can use either Keplr or gaiad. To do so, you need to:
  1. Install Ledger Live on your machine.
  2. Using Ledger Live, update your Ledger Nano S with the latest firmware.
  3. On the Ledger Live application, navigate to the Manager menu. Ledger Live Manager
  4. Connect your Ledger Nano device and allow Ledger Manager from it.
  5. On the Ledger Live application, search for Cosmos. Search for Cosmos app
  6. Install the Cosmos application by clicking on Install.
To see the Cosmos application when you search for it, you might need to activate the Developer Mode, located in the Experimental features tab of the Ledger Live application.
Enable Developer Mode

Keplr + Ledger Nano

Note: You need to install the Cosmos app on your Ledger Nano before following this section
  1. Connect your Ledger device to your computer, unlock it with the PIN and open the Cosmos app.
  2. Install the Keplr browser extension.
  3. Click on the Keplr extension icon and select Import Ledger and choose an account name and password.
  4. Make sure your Ledger device is unlocked and has the Cosmos app open and then follow the instructions on the Keplr pop-up.
That’s it! You can now use Keplr with your Ledger Nano S. You can use the Keplr web app to get a more detailed overview of your Cosmos account. Note: Each time you will send a transaction, you will need to confirm it on your Ledger device. Indication will be prompted from the Keplr interface

(Optional) Confirm your address

You can double check that Keplr is displaying the correct address directly on your Ledger Nano device. To do so:
  1. Connect your Ledger to your computer and open the Cosmos application on the device.
  2. Once the Cosmos app is open, click on the right button to access the Show Address option.
  3. Click on both button, then select Account 0 and Index 0.
You should now see the same address that is displayed on the Keplr extension. To learn more about using Keplr, we suggest you have a look at their documentation. You can also have a look at the Ledger support page for more details.

Gaia CLI + Ledger Nano

Note: You need to install the Cosmos app on your Ledger Nano before following this section The tool used to generate addresses and transactions on the Cosmos Hub network is gaiad. Here is how to get started. If using a CLI tool is unfamiliar to you, scroll down and follow instructions for using the Keplr wallet instead.

Before you Begin

Verify that gaiad is installed correctly with the following command
gaiad version --long

➜ cosmos-sdk: 0.34.3
git commit: 67ab0b1e1d1e5b898c8cbdede35ad5196dba01b2
vendor hash: 0341b356ad7168074391ca7507f40b050e667722
build tags: netgo ledger
go version go1.11.5 darwin/amd64

Add your Ledger key

  • Connect and unlock your Ledger device.
  • Open the Cosmos app on your Ledger.
  • Create an account in gaiad from your ledger key.
Be sure to change the keyName parameter to be a meaningful name. The ledger flag tells gaiad to use your Ledger to seed the account.
gaiad keys add <keyName> --ledger

➜ NAME: TYPE: ADDRESS:     PUBKEY:
<keyName> ledger cosmos1... cosmospub1...
Cosmos uses HD Wallets. This means you can setup many accounts using the same Ledger seed. To create another account from your Ledger device, run (change the integer i to some value >= 0 to choose the account for HD derivation):
gaiad keys add <secondKeyName> --ledger --account <i>

Confirm your address

Run this command to display your address on the device. Use the keyName you gave your ledger key. The -d flag is supported in version 1.5.0 and higher.
gaiad keys show <keyName> -d
Confirm that the address displayed on the device matches that displayed when you added the key.

Connect to a full node

Next, you need to configure gaiad with the URL of a Cosmos full node and the appropriate chain_id. In this example we connect to the public load balanced full node operated by Chorus One on the cosmoshub-2 chain. But you can point your gaiad to any Cosmos full node. Be sure that the chain-id is set to the same chain as the full node.
gaiad config node https://cosmos.chorus.one:26657
gaiad config chain_id cosmoshub-2
Test your connection with a query such as:
gaiad query staking validators
To run your own full node locally read more here..

Sign a transaction

You are now ready to start signing and sending transactions. Send a transaction with gaiad using the tx send command.
gaiad tx bank send --help # to see all available options.
Be sure to unlock your device with the PIN and open the Cosmos app before trying to run these commands
Use the keyName you set for your Ledger key and gaia will connect with the Cosmos Ledger app to then sign your transaction.
gaiad tx bank send <keyName> <destinationAddress> <amount><denomination>
When prompted with confirm transaction before signing, Answer Y. Next you will be prompted to review and approve the transaction on your Ledger device. Be sure to inspect the transaction JSON displayed on the screen. You can scroll through each field and each message. Scroll down to read more about the data fields of a standard transaction object. Now, you are all set to start sending transactions on the network.

Receive funds

To receive funds to the Cosmos account on your Ledger device, retrieve the address for your Ledger account (the ones with TYPE ledger) with this command:
gaiad keys list

➜ NAME: TYPE: ADDRESS:     PUBKEY:
<keyName> ledger cosmos1... cosmospub1...

Further documentation

Not sure what gaiad can do? Simply run the command without arguments to output documentation for the commands in supports.
The gaiad help commands are nested. So $ gaiad will output docs for the top level commands (status, config, query, and tx). You can access documentation for sub commands with further help commands.For example, to print the query commands:
gaiad query --help
Or to print the tx (transaction) commands:
gaiad tx --help

The Cosmos Standard Transaction

Transactions in Cosmos embed the Standard Transaction type from the Cosmos SDK. The Ledger device displays a serialized JSON representation of this object for you to review before signing the transaction. Here are the fields and what they mean:
  • chain-id: The chain to which you are broadcasting the tx, such as the gaia-13003 testnet or cosmoshub-2: mainnet.
  • account_number: The global id of the sending account assigned when the account receives funds for the first time.
  • sequence: The nonce for this account, incremented with each transaction.
  • fee: JSON object describing the transaction fee, its gas amount and coin denomination
  • memo: optional text field used in various ways to tag transactions.
  • msgs_<index>/<field>: The array of messages included in the transaction. Double click to drill down into nested fields of the JSON.

Support

For further support, start by looking over the posts in our forum Feel welcome to reach out in our Telegram channel to ask for help. Here are a few relevant and helpful tutorials from the wonderful Cosmos community: