Solana CLIでKeypair指定してアドレス、残高照会、エアドロップ

コマンド

Keypairファイルのセット

Keypairを作成して、CLIからそれを読み込むようにしたい場合。

% solana config set --keypair ~/.config/solana/id.json

Keypair指定のアドレス確認

「% solana balance --keypair [Keypairファイル]」で確認できる。
(buildしたときに生成されるKeypairを指定する)

% solana address --keypair dist/program/helloworld-keypair.json
DkxmbKVexKDKJpeNYjahGDJP1WFytXx1i4kH3xzCGqj2

Keypair指定の残高照会

「% solana balance --keypair [Keypairファイル]」で実施できる。
(buildしたときに生成されるKeypairを指定する)
アドレス指定のやり方はわからなかった。

% solana balance --keypair dist/program/helloworld-keypair.json
4.57795376 SOL

アドレス指定のエアドロップ

「% solana airdrop [金額] [アドレス]」で確認できる。

% solana airdrop 5 DkxmbKVexKDKJpeNYjahGDJP1WFytXx1i4kH3xzCGqj2
Requesting airdrop of 5 SOL

Signature: BPgM5yLHRGpJ8VavMJGpGBgsnwRb5eyVbcf1Eh2kaUVUVzWoCLsJmZFACnhh8vTmPkJLj7N1cUDhXRmwQoeb8c6

9.57795376 SOL

ローカル生成アドレスの場合

引数指定しない場合はウォレットアドレスをローカルで生成したときのデフォルトのKeypairが利用される。Keypairの場所は以下コマンドで確認できる。

% solana config get
Config File: /Users/user/.config/solana/cli/config.yml
RPC URL: https://api.devnet.solana.com
WebSocket URL: wss://api.devnet.solana.com/ (computed)
Keypair Path: /Users/user/.config/solana/id.json
Commitment: confirmed
% solana balance
5.41478452 SOL
 % solana airdrop 1
Requesting airdrop of 1 SOL

Signature: kKvnm1ZxVZY1Yf3wHQjhFDasVNRJbdUnKh1mfTxFkZcQ3TkZfGwr7czvun9PqnyoU4iuXPMSXdHXbpQMjTb8jKH

6.41478452 SOL

コマンドヘルプ

「[コマンド] [サブコマンド] -h」でヘルプ表示可能。

% solana address -h

% solana address -h
solana-address
Get your public key

USAGE:
    solana address [FLAGS] [OPTIONS]

FLAGS:
        --confirm-key                    Confirm key on device; only relevant if using remote wallet
    -h, --help                           Prints help information
        --no-address-labels              Do not use address labels in the output
        --skip-seed-phrase-validation    Skip validation of seed phrases. Use this if your phrase does not use the BIP39
                                         official English word list
    -V, --version                        Prints version information
    -v, --verbose                        Show additional information

OPTIONS:
        --commitment <COMMITMENT_LEVEL>    Return information at the selected commitment level [possible values:
                                           processed, confirmed, finalized]
    -C, --config <FILEPATH>                Configuration file to use [default:
                                           /Users/user/.config/solana/cli/config.yml]
    -u, --url <URL_OR_MONIKER>             URL for Solana's JSON RPC or moniker (or their first letter): [mainnet-beta,
                                           testnet, devnet, localhost]
    -k, --keypair <KEYPAIR>                Filepath or URL to a keypair
        --output <FORMAT>                  Return information in specified output format [possible values: json, json-
                                           compact]
        --ws <URL>                         WebSocket URL for the solana cluster

% solana balance -h

% solana balance -h
solana-balance
Get your balance

USAGE:
    solana balance [FLAGS] [OPTIONS] [ACCOUNT_ADDRESS]

FLAGS:
    -h, --help                           Prints help information
        --lamports                       Display balance in lamports instead of SOL
        --no-address-labels              Do not use address labels in the output
        --skip-seed-phrase-validation    Skip validation of seed phrases. Use this if your phrase does not use the BIP39
                                         official English word list
    -V, --version                        Prints version information
    -v, --verbose                        Show additional information

OPTIONS:
        --commitment <COMMITMENT_LEVEL>    Return information at the selected commitment level [possible values:
                                           processed, confirmed, finalized]
    -C, --config <FILEPATH>                Configuration file to use [default:
                                           /Users/user/.config/solana/cli/config.yml]
    -u, --url <URL_OR_MONIKER>             URL for Solana's JSON RPC or moniker (or their first letter): [mainnet-beta,
                                           testnet, devnet, localhost]
    -k, --keypair <KEYPAIR>                Filepath or URL to a keypair
        --output <FORMAT>                  Return information in specified output format [possible values: json, json-
                                           compact]
        --ws <URL>                         WebSocket URL for the solana cluster

ARGS:
    <ACCOUNT_ADDRESS>    The account address of the balance to check. , one of:
                           * a base58-encoded public key
                           * a path to a keypair file
                           * a hyphen; signals a JSON-encoded keypair on stdin
                           * the 'ASK' keyword; to recover a keypair via its seed phrase
                           * a hardware wallet keypair URL (i.e. usb://ledger)

% solana airdrop -h

% solana airdrop -h
solana-airdrop
Request SOL from a faucet

USAGE:
    solana airdrop [FLAGS] [OPTIONS] <AMOUNT> [RECIPIENT_ADDRESS]

FLAGS:
    -h, --help                           Prints help information
        --no-address-labels              Do not use address labels in the output
        --skip-seed-phrase-validation    Skip validation of seed phrases. Use this if your phrase does not use the BIP39
                                         official English word list
    -V, --version                        Prints version information
    -v, --verbose                        Show additional information

OPTIONS:
        --commitment <COMMITMENT_LEVEL>    Return information at the selected commitment level [possible values:
                                           processed, confirmed, finalized]
    -C, --config <FILEPATH>                Configuration file to use [default:
                                           /Users/user/.config/solana/cli/config.yml]
    -u, --url <URL_OR_MONIKER>             URL for Solana's JSON RPC or moniker (or their first letter): [mainnet-beta,
                                           testnet, devnet, localhost]
    -k, --keypair <KEYPAIR>                Filepath or URL to a keypair
        --output <FORMAT>                  Return information in specified output format [possible values: json, json-
                                           compact]
        --ws <URL>                         WebSocket URL for the solana cluster

ARGS:
    <AMOUNT>               The airdrop amount to request, in SOL
    <RECIPIENT_ADDRESS>    The account address of airdrop recipient. , one of:
                             * a base58-encoded public key
                             * a path to a keypair file
                             * a hyphen; signals a JSON-encoded keypair on stdin
                             * the 'ASK' keyword; to recover a keypair via its seed phrase
                             * a hardware wallet keypair URL (i.e. usb://ledger)

参考