Solana 開發學習之Solana 基礎知識 Install the Solana CLI 相關鏈接 https://docs.solanalabs.com/cli/install https://solanacookbook.com/zh/getting-started/installation ...
Solana 開發學習之Solana 基礎知識
Install the Solana CLI
相關鏈接
- https://docs.solanalabs.com/cli/install
- https://solanacookbook.com/zh/getting-started/installation.html#安裝命令行工具
- https://www.solanazh.com/course/1-4
- https://solana.com/zh/developers/guides/getstarted/setup-local-development
實操
- 安裝
sh -c "$(curl -sSfL https://release.solana.com/v1.18.2/install)"
downloading v1.18.2 installer
✨ 1.18.2 initialized
Adding
export PATH="/Users/qiaopengjun/.local/share/solana/install/active_release/bin:$PATH" to /Users/qiaopengjun/.profile
Adding
export PATH="/Users/qiaopengjun/.local/share/solana/install/active_release/bin:$PATH" to /Users/qiaopengjun/.zprofile
Adding
export PATH="/Users/qiaopengjun/.local/share/solana/install/active_release/bin:$PATH" to /Users/qiaopengjun/.bash_profile
Close and reopen your terminal to apply the PATH changes or run the following in your existing shell:
export PATH="/Users/qiaopengjun/.local/share/solana/install/active_release/bin:$PATH"
- 配置環境變數
vim .zshrc
# 複製並粘貼下麵命令以更新 PATH
export PATH="/Users/qiaopengjun/.local/share/solana/install/active_release/bin:$PATH"
- 通過運行以下命令確認您已安裝了所需的 Solana 版本:
solana --version
# 實操
solana --version
solana-cli 1.18.2 (src:13656e30; feat:3352961542, client:SolanaLabs)
- 切換版本
solana-install init 1.16.4
設置網路環境
官方RPC地址分別是:
- DevNet: https://api.devnet.solana.com
- TestNet: https://api.testnet.solana.com
- MainNet: https://api.mainnet-beta.solana.com
相關鏈接
實操
solana config set --url https://api.devnet.solana.com
Config File: /Users/qiaopengjun/.config/solana/cli/config.yml
RPC URL: https://api.devnet.solana.com
WebSocket URL: wss://api.devnet.solana.com/ (computed)
Keypair Path: /Users/qiaopengjun/.config/solana/id.json
Commitment: confirmed
創建賬號
相關鏈接
Check your installation
運行以下命令檢查 solana-keygen 是否安裝正確:
solana-keygen --version
# 實操
solana-keygen --version
solana-keygen 1.18.2 (src:13656e30; feat:3352961542, client:SolanaLabs)
使用 solana-keygen 工具,可以生成新的種子短語,以及從現有的種子短語和(可選的)密碼短語派生一個密鑰對。
種子短語和口令短語可以作為紙錢包一起使用。只要您保持您的種子短語和密碼存儲安全,您可以使用它們訪問您的帳戶。
For full usage details, run:
solana-keygen new --help
solana-keygen-new
Generate new keypair file from a random seed phrase and optional BIP39 passphrase
USAGE:
solana-keygen new [OPTIONS]
OPTIONS:
-C, --config <FILEPATH>
Configuration file to use [default: /Users/qiaopengjun/.config/solana/cli/config.yml]
--derivation-path [<DERIVATION_PATH>...]
Derivation path. All indexes will be promoted to hardened. If arg is not presented then
derivation path will not be used. If arg is presented with empty DERIVATION_PATH value
then m/44'/501'/0'/0' will be used.
-f, --force
Overwrite the output file if it exists
-h, --help
Print help information
--language <LANGUAGE>
Specify the mnemonic language that will be present in the generated seed phrase
[default: english] [possible values: english, chinese-simplified, chinese-traditional,
japanese, spanish, korean, french, italian]
--no-bip39-passphrase
Do not prompt for a BIP39 passphrase
--no-outfile
Only print a seed phrase and pubkey. Do not output a keypair file
-o, --outfile <FILEPATH>
Path to generated file
-s, --silent
Do not display seed phrase. Useful when piping output to other programs that prompt for
user input, like gpg
--word-count <NUMBER>
Specify the number of words that will be present in the generated seed phrase [default:
12] [possible values: 12, 15, 18, 21, 24]
實操
sosolana-keygen new --force
Generating a new keypair
For added security, enter a BIP39 passphrase
NOTE! This passphrase improves security of the recovery seed phrase NOT the
keypair file itself, which is stored as insecure plain text
BIP39 Passphrase (empty for none):
Wrote new keypair to /Users/qiaopengjun/.config/solana/id.json
=================================================================================
pubkey: 賬號的地址
=================================================================================
Save this seed phrase and your BIP39 passphrase to recover your new keypair:
對應的BIP39的助記詞
=================================================================================
查看當前賬號的地址,Keypair文件的中的公鑰:
solana-keygen pubkey
申請水龍頭
solana airdrop 1
Requesting airdrop of 1 SOL
Signature: GTVSLYa9Vm1FfjBSDVxf8cBL6D47caXHuETRbdD3eQ5C36ZA261MLJXBxzWU2HoiaedAAmBdiy17YFnSaiWsvW3
1 SOL
Solana CLI Reference and Usage
查看當前賬號的餘額
solana balance
1 SOL
- https://solscan.io/tx/GTVSLYa9Vm1FfjBSDVxf8cBL6D47caXHuETRbdD3eQ5C36ZA261MLJXBxzWU2HoiaedAAmBdiy17YFnSaiWsvW3?cluster=devnet
- https://explorer.solana.com/tx/GTVSLYa9Vm1FfjBSDVxf8cBL6D47caXHuETRbdD3eQ5C36ZA261MLJXBxzWU2HoiaedAAmBdiy17YFnSaiWsvW3?cluster=devnet
查看 config
cat .config/solana/cli/config.yml
---
json_rpc_url: https://api.devnet.solana.com
websocket_url: ''
keypair_path: /Users/qiaopengjun/.config/solana/id.json
address_labels:
'11111111111111111111111111111111': System Program
commitment: confirmed
轉賬
solana transfer --allow-unfunded-recipient H6Su7YsGK5mMASrZvJ51nt7oBzD88V8FKSBPNnRG1u3k 0.01
Signature: 5t9ysYELu2Gv1jc7SDXzmZotLUDhkUwuSd48tH2QSqJy8iTYkXD7Sf9fNVxXhkcUZsCy7s7WvsddRbxrfK3tKmEg
練習
通過命令行,發行一個代幣。並給自己賬號mint一定數量的代幣。 並通過插件錢包或者命令行的方式給其他同學空投該代幣
-
設置環境為開發環境
-
創建賬號
-
申請水龍頭
-
創建Token
spl-token create-token
Creating token E7eHC3g4QsFXuaBe3X2wVr54yEvHK8K8fq6qrgB64djx under program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA
Address: E7eHC3g4QsFXuaBe3X2wVr54yEvHK8K8fq6qrgB64djx
Decimals: 9
Signature: 51yuJ91agCKxYWEbLgMfEq5BWBTaFZoezxfnKVoTmrGi59S44q7nKkfVjsCpMJNVLwW8AKuiNbNKb4JSUzLHQy9d
- https://solscan.io/token/E7eHC3g4QsFXuaBe3X2wVr54yEvHK8K8fq6qrgB64djx?cluster=devnet
- https://solscan.io/tx/51yuJ91agCKxYWEbLgMfEq5BWBTaFZoezxfnKVoTmrGi59S44q7nKkfVjsCpMJNVLwW8AKuiNbNKb4JSUzLHQy9d?cluster=devnet
- 創建Token Account
spl-token create-account E7eHC3g4QsFXuaBe3X2wVr54yEvHK8K8fq6qrgB64djx
Creating account HDv1RgdHjrjSdnTFJsMqQGPcKTiuF7zLjhNaSd7ihbKh
Signature: 3shwWeUAiFYTE2qfARofhyPRtHvtGBRNf2oB8AoxsAX11mEbUsxk2q35YSmWBcBQEnhS2t2LsBnQ9bjt4m2WR3qt
- Token Account Mint
spl-token mint E7eHC3g4QsFXuaBe3X2wVr54yEvHK8K8fq6qrgB64djx 100 HDv1RgdHjrjSdnTFJsMqQGPcKTiuF7zLjhNaSd7ihbKh
Minting 100 tokens
Token: E7eHC3g4QsFXuaBe3X2wVr54yEvHK8K8fq6qrgB64djx
Recipient: HDv1RgdHjrjSdnTFJsMqQGPcKTiuF7zLjhNaSd7ihbKh
Signature: 4XdNt4yotJdcKN1JGSqm4CL8tQ8vELzGLNGT8ChucQWmofSBpSz2jU8gHmET18PBu2Z3ZGt9RkzRAwuZ5DdBEzba
- 查詢餘額
spl-token balance E7eHC3g4QsFXuaBe3X2wVr54yEvHK8K8fq6qrgB64djx
100
- 轉賬
spl-token transfer --fund-recipient E7eHC3g4QsFXuaBe3X2wVr54yEvHK8K8fq6qrgB64djx 10 H6Su7YsGK5mMASrZvJ51nt7oBzD88V8FKSBPNnRG1u3k
Transfer 10 tokens
Sender: HDv1RgdHjrjSdnTFJsMqQGPcKTiuF7zLjhNaSd7ihbKh
Recipient: H6Su7YsGK5mMASrZvJ51nt7oBzD88V8FKSBPNnRG1u3k
Recipient associated token account: HY1GfCQabyUMFRGpDu3eFoVW3ny8ifHKVZ8LbvzbDPsK
Funding recipient: HY1GfCQabyUMFRGpDu3eFoVW3ny8ifHKVZ8LbvzbDPsK
Signature: 4jbcoJYS6ZGPcUmHpqTnxeLHfQxvUqQQnzgoJCgWWA1LpKkKWRA5y2FZ7rDQ2v4NBBcuUJqh37A9p92mvbTmS6iY
- 查詢餘額
spl-token balance E7eHC3g4QsFXuaBe3X2wVr54yEvHK8K8fq6qrgB64djx
90
本文來自博客園,作者:尋月隱君,轉載請註明原文鏈接:https://www.cnblogs.com/QiaoPengjun/p/18025318