前文演示的是第三方钱包的使用 Solana的第三方钱包使用
Solana官方为我们提供了一套命令行工具来实现对Solana的操作,支持Mac/Linux/Windows,下面我们以Mac作为演示平台进行操作。
安装
luca@LucadeMacBook-Air ~ % sh -c "$(curl -sSfL https://release.solana.com/stable/install)"
downloading stable installer
✨ stable commit d0ed878 initialized
Adding
export PATH="/Users/luca/.local/share/solana/install/active_release/bin:$PATH" to /Users/luca/.profile
Adding
export PATH="/Users/luca/.local/share/solana/install/active_release/bin:$PATH" to /Users/luca/.zprofile
Adding
export PATH="/Users/luca/.local/share/solana/install/active_release/bin:$PATH" to /Users/luca/.bash_profile
Close and reopen your terminal to apply the PATH changes or run the following in your existing shell:
export PATH="/Users/luca/.local/share/solana/install/active_release/bin:$PATH"
按照提示设置好Path,验证是否安装成功
luca@LucadeMacBook-Air ~ % export PATH="/Users/luca/.local/share/solana/install/active_release/bin:$PATH"
luca@LucadeMacBook-Air ~ %
luca@LucadeMacBook-Air ~ %
luca@LucadeMacBook-Air ~ % solana --version
solana-cli 1.17.25 (src:d0ed878d; feat:3580551090, client:SolanaLabs)
设置网络环境
Solana的网络生态划分为开发网devnet、测试网testnnet和主网mainnet三个主要环境。开发网专为Solana节点的开发者设计,更新频繁,旨在提供最新的功能和技术支持。测试网则为DApp开发者提供一个相对稳定的环境,用于测试他们的应用程序。而主网则是正式环境,其中的代币具有真实的价值。
在开发网上,开发者可以申请空投的测试代币,以便进行开发和测试。
这里我们选取的是测试网testnet
luca@LucadeMacBook-Air ~ % solana config set --url https://api.testnet.solana.com
Config File: /Users/luca/.config/solana/cli/config.yml
RPC URL: https://api.testnet.solana.com
WebSocket URL: wss://api.testnet.solana.com/ (computed)
Keypair Path: /Users/luca/.config/solana/id.json
Commitment: confirmed
新建账户
luca@LucadeMacBook-Air ~ % solana-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):
Enter same passphrase again:
Wrote new keypair to /Users/luca/.config/solana/id.json
======================================================================
pubkey: E3NAyseUZrgwSbYe2g47TuFJr5CxAeneK63mR4Ufbqhh
======================================================================
Save this seed phrase and your BIP39 passphrase to recover your new keypair:
juice vocal head squirrel minor scene nasty sweet arena best pear cave
======================================================================
设定好助记词(助记词可用来恢复账号),keypair被加密存在"/Users/you/.config/solana/id.json"。
其中pubkey就是你的钱包地址,也可以通过如下命令可以查看当前账号的地址,也就是上面的Keypair文件的中的公钥
luca@LucadeMacBook-Air ~ % solana-keygen pubkey
E3NAyseUZrgwSbYe2g47TuFJr5CxAeneK63mR4Ufbqhh
查看账户余额
luca@LucadeMacBook-Air ~ % solana balance
0 SOL
申请水龙头
现在直接通过命令行领会失败
luca@LucadeMacBook-Air ~ % solana airdrop 1
Requesting airdrop of 1 SOL
Error: unable to confirm transaction. This can happen in situations such as transaction expiration and insufficient fee-payer funds
这里我们选择第三方水龙头网站来领取 faucet
再次查询余额
luca@LucadeMacBook-Air ~ % solana balance
1 SOL
链上查看
转账
luca@LucadeMacBook-Air ~ % solana transfer 6nmqFHKGZP8AXpdh3ynwV4GQS1cc64wG8e8dZUgX4RoM 0.1
Signature: 5ogR3R3qjkamiGTEP9jnoBZ9vJirjMHm93fXCmkpGDnsuvz1XBibYaojrPnww4ob4LXpqdTgzhSogEFMHhxQisft
查看余额
luca@LucadeMacBook-Air ~ % solana balance
0.899995 SOL
浏览器查看