Solana 开发学习之Solana 基础知识

Solana 开发学习之Solana 基础知识

Install the Solana CLI

相关链接

实操

  • 安装
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地址分别是:

相关链接

实操

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

查看 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一定数量的代币。 并通过插件钱包或者命令行的方式给其他同学空投该代币

  1. 设置环境为开发环境

  2. 创建账号

  3. 申请水龙头

  4. 创建Token

spl-token create-token
Creating token E7eHC3g4QsFXuaBe3X2wVr54yEvHK8K8fq6qrgB64djx under program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA

Address:  E7eHC3g4QsFXuaBe3X2wVr54yEvHK8K8fq6qrgB64djx
Decimals:  9

Signature: 51yuJ91agCKxYWEbLgMfEq5BWBTaFZoezxfnKVoTmrGi59S44q7nKkfVjsCpMJNVLwW8AKuiNbNKb4JSUzLHQy9d

  1. 创建Token Account
spl-token create-account E7eHC3g4QsFXuaBe3X2wVr54yEvHK8K8fq6qrgB64djx
Creating account HDv1RgdHjrjSdnTFJsMqQGPcKTiuF7zLjhNaSd7ihbKh

Signature: 3shwWeUAiFYTE2qfARofhyPRtHvtGBRNf2oB8AoxsAX11mEbUsxk2q35YSmWBcBQEnhS2t2LsBnQ9bjt4m2WR3qt

  1. Token Account Mint
spl-token mint E7eHC3g4QsFXuaBe3X2wVr54yEvHK8K8fq6qrgB64djx 100 HDv1RgdHjrjSdnTFJsMqQGPcKTiuF7zLjhNaSd7ihbKh
Minting 100 tokens
  Token: E7eHC3g4QsFXuaBe3X2wVr54yEvHK8K8fq6qrgB64djx
  Recipient: HDv1RgdHjrjSdnTFJsMqQGPcKTiuF7zLjhNaSd7ihbKh

Signature: 4XdNt4yotJdcKN1JGSqm4CL8tQ8vELzGLNGT8ChucQWmofSBpSz2jU8gHmET18PBu2Z3ZGt9RkzRAwuZ5DdBEzba

  1. 查询余额
spl-token balance E7eHC3g4QsFXuaBe3X2wVr54yEvHK8K8fq6qrgB64djx
100
  1. 转账
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

  1. 查询余额
spl-token balance E7eHC3g4QsFXuaBe3X2wVr54yEvHK8K8fq6qrgB64djx
90

posted @ 2024-02-21 15:30  寻月隐君  阅读(500)  评论(0编辑  收藏  举报