forked from Fankouzu/solana-basic-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Fankouzu#7 from ben46/main
- Loading branch information
Showing
4 changed files
with
279 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# 使用 Solana CLI 连接到集群 | ||
|
||
## 配置命令行工具 | ||
|
||
查看当前连接的集群 | ||
|
||
```sh | ||
$ solana config get | ||
``` | ||
|
||
使用solana config set命令来连接到特定的集群。设置后,任何未来的子命令将会发送/接收来自该集群的信息。 | ||
|
||
例如,要连接到 Devnet 集群,请运行: | ||
|
||
```sh | ||
$ solana config set --url https://api.devnet.solana.com | ||
``` | ||
|
||
## 确保版本匹配 | ||
|
||
最好本地CLI版本大于或等于集群版本。 | ||
|
||
要获取本地安装的 CLI 版本,请运行: | ||
|
||
```sh | ||
$ solana --version | ||
``` | ||
|
||
要获取集群版本,请运行: | ||
|
||
```sh | ||
$ solana cluster-version | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
# 使用 Solana CLI 质押 SOL | ||
|
||
接收到 SOL 后,你可以考虑将其用于委托给验证者。Stake 是我们在 stake 账户中称为的代币。Solana 通过委托给验证者的 stake 数量来权衡验证者的投票权,从而使这些验证者在确定区块链中下一个有效交易块时具有更多的影响力。Solana 然后定期生成新的 SOL 以奖励委托者和验证者。你委托的 stake 越多,就可以获得更多的奖励。 | ||
|
||
## 创建质押账户 | ||
|
||
|
||
如果您想委托质押, 您需要两步操作: | ||
|
||
1. 您需要将一些token转入stake账户。 | ||
2. 要创建stake帐户,您将需要密钥对, 公钥将作为stake账户的地址。 这里不需要密码或加密;创建完之后, 这个密钥对就会被丢弃. | ||
|
||
#### 第一步: 生成密钥对 | ||
``` | ||
solana-keygen new --no-passphrase -o stake-account.json | ||
``` | ||
|
||
输出公钥(stake账户地址): | ||
|
||
``` | ||
pubkey: GKvqsuNcnwWqPzzuhLmGi4rzzh55FhJtGizkhHaEJqiV | ||
``` | ||
|
||
复制公钥并妥善保管。后面要用. | ||
|
||
#### 第二步: 创建一个stake账户,并转入代币: | ||
|
||
``` | ||
solana create-stake-account --from <KEYPAIR> stake-account.json <AMOUNT> \ | ||
--stake-authority <KEYPAIR> --withdraw-authority <KEYPAIR> \ | ||
--fee-payer <KEYPAIR> | ||
``` | ||
|
||
`KEYPAIR`: 你的密钥对 | ||
|
||
`AMOUNT`: 转移的代币数量 | ||
|
||
`stake-account.json`: 你的stake账户的公钥文件路径 | ||
|
||
现在可以删除 `stake-account.json` 文件了。要授权其他操作,您可以使用 --stake-authority 或 --withdraw-authority 密钥对,而不是 `stake-account.json`。 | ||
|
||
使用 solana stake-account 命令查看新的权益账户: | ||
|
||
``` | ||
solana stake-account <STAKE_ACCOUNT_ADDRESS> | ||
``` | ||
|
||
输出将类似于以下内容: | ||
|
||
``` | ||
Total Stake: 5000 SOL | ||
Stake account is undelegated | ||
Stake Authority: EXU95vqs93yPeCeAU7mPPu6HbRUmTFPEiGug9oCdvQ5F | ||
Withdraw Authority: EXU95vqs93yPeCeAU7mPPu6HbRUmTFPEiGug9oCdvQ5F | ||
``` | ||
|
||
## 设置质押和取款权限 | ||
|
||
|
||
质押和取款权限可以在创建账户时通过 --stake-authority 和 --withdraw-authority 选项来设置,或者后面通过 solana stake-authorize 命令来设置。 | ||
|
||
例如,要设置一个新的质押权限,运行: | ||
|
||
``` | ||
solana stake-authorize <STAKE_ACCOUNT_ADDRESS> \ | ||
--stake-authority <KEYPAIR> --new-stake-authority <PUBKEY> \ | ||
--fee-payer <KEYPAIR> | ||
``` | ||
|
||
`KEYPAIR`: stake账户的权限所有者 | ||
|
||
`STAKE_ACCOUNT_ADDRESS`: stake账户地址 | ||
|
||
`PUBKEY`: 新的权限所有者 | ||
|
||
这里做了一个质押的权限的移交. | ||
|
||
|
||
## 委托质押 | ||
|
||
要将您的质押委托给验证人,您需要知道它的投票账户地址。通过使用`solana validators`命令查询群集以获取所有验证人及其投票账户列表来找到它: | ||
|
||
``` | ||
solana validators | ||
``` | ||
|
||
每行的第一列包含验证人的身份,第二列是投票账户地址。 | ||
|
||
选择一个验证人 | ||
|
||
运行以下命令, 把你的质押委托给验证人: | ||
|
||
``` | ||
solana delegate-stake --stake-authority <KEYPAIR> <STAKE_ACCOUNT_ADDRESS> <VOTE_ACCOUNT_ADDRESS> \ | ||
--fee-payer <KEYPAIR> | ||
``` | ||
|
||
`VOTE_ACCOUNT_ADDRESS`: 验证人地址 | ||
|
||
`KEYPAIR`: 你的密钥对 | ||
|
||
`STAKE_ACCOUNT_ADDRESS`: 你的stake账户 | ||
|
||
委托后,使用solana stake-account观察stake账户的变化: | ||
|
||
``` | ||
solana stake-account <STAKE_ACCOUNT_ADDRESS> | ||
``` | ||
|
||
您将在输出中看到新的字段"代币委托"和"代币委托账户地址"。 输出将类似于这样: | ||
``` | ||
Total Stake: 5000 SOL | ||
Credits Observed: 147462 | ||
Delegated Stake: 4999.99771712 SOL | ||
Delegated Vote Account Address: CcaHc2L43ZWjwCHART3oZoJvHLAe9hzT2DJNUpBzoTN1 | ||
Stake activates starting from epoch: 42 | ||
Stake Authority: EXU95vqs93yPeCeAU7mPPu6HbRUmTFPEiGug9oCdvQ5F | ||
Withdraw Authority: EXU95vqs93yPeCeAU7mPPu6HbRUmTFPEiGug9oCdvQ5F | ||
``` | ||
|
||
|
||
## 取消委托 | ||
|
||
您可以使用 solana deactivate-stake 取消委托: | ||
|
||
``` | ||
solana deactivate-stake --stake-authority <KEYPAIR> <STAKE_ACCOUNT_ADDRESS> \ | ||
--fee-payer <KEYPAIR> | ||
``` | ||
|
||
请注意,刚刚委托的权益账户有冷却期, 不能马上取消委托. | ||
|
||
## 取出质押 | ||
|
||
``` | ||
solana withdraw-stake --withdraw-authority <KEYPAIR> <STAKE_ACCOUNT_ADDRESS> <RECIPIENT_ADDRESS> <AMOUNT> \ | ||
--fee-payer <KEYPAIR> | ||
``` | ||
|
||
`RECIPIENT_ADDRESS`: 取出到哪个地址 | ||
|
||
`KEYPAIR`: 你的密钥对 | ||
|
||
`STAKE_ACCOUNT_ADDRESS`: 现在的stake账户 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# 使用本地集群进行开发 | ||
|
||
使用`solana-test-validator`在本地电脑上运行单节点集群。便于开发 | ||
|
||
## 优点 | ||
|
||
* 无 RPC 速率限制 | ||
* 无领水限制 | ||
* 直接链上程序(--bpf-program ...部署 ) | ||
* 从公共集群克隆帐户,包括程序 (--clone ...) | ||
* 从文件加载帐户 | ||
* 可配置的交易历史记录保留(--limit-ledger-size ...) | ||
* 可配置的纪元长度(--slots-per-epoch ...) | ||
* 跳转到任意插槽 (--warp-slot ...) | ||
|
||
## 安装 | ||
|
||
包含在CLI的安装里面了, 确认你安装了CLI工具包, 继续阅读. | ||
|
||
## 运行 | ||
|
||
首先看一下配置选项 | ||
|
||
``` | ||
solana-test-validator --help | ||
``` | ||
|
||
接下来启动测试验证器 | ||
``` | ||
solana-test-validator | ||
``` | ||
|
||
详情请参阅附录一默认情况下,进程运行时会打印基本状态信息。 | ||
``` | ||
Ledger location: test-ledger | ||
Log: test-ledger/validator.log | ||
Identity: EPhgPANa5Rh2wa4V2jxt7YbtWa3Uyw4sTeZ13cQjDDB8 | ||
Genesis Hash: 4754oPEMhAKy14CZc8GzQUP93CB4ouELyaTs4P8ittYn | ||
Version: 1.6.7 | ||
Shred Version: 13286 | ||
Gossip Address: 127.0.0.1:1024 | ||
TPU Address: 127.0.0.1:1027 | ||
JSON RPC URL: http://127.0.0.1:8899 | ||
⠈ 00:36:02 | Processed Slot: 5142 | Confirmed Slot: 5142 | Finalized Slot: 5110 | Snapshot Slot: 5100 | Transactions: 5142 | ◎499.974295000 | ||
``` | ||
|
||
保持终端不要关闭 | ||
|
||
|
||
## 命令行交互 | ||
|
||
打开一个新终端, 连接本地集群 | ||
|
||
``` | ||
solana config set --url http://127.0.0.1:8899 | ||
``` | ||
|
||
验证 CLI 工具套件配置 | ||
``` | ||
solana genesis-hash | ||
``` | ||
|
||
请注意:结果应该与solana-test-validator状态输出中的Genesis Hash字段匹配 | ||
|
||
查看钱包余额 | ||
|
||
``` | ||
solana balance | ||
``` | ||
|
||
请注意, 如果报错:`没有这样的文件或目录(操作系统错误2)`意味着默认钱包尚不存在。请用solana-keygen new命令创建钱包. | ||
|
||
如果钱包的SOL余额为零,则通过`Solana airdrop 10`来进行一些本地SOL空投 | ||
|
||
执行基本转账交易 | ||
|
||
``` | ||
solana transfer EPhgPANa5Rh2wa4V2jxt7YbtWa3Uyw4sTeZ13cQjDDB8 1 | ||
``` | ||
|
||
监视来自链上程序的消息输出 | ||
``` | ||
solana logs | ||
``` | ||
|
||
请注意:此命令需要在独立的终端中运行。 | ||
|
||
|
||
|
||
|
||
|