solana-cli 1.16.8 (src:b19d7219; feat:3712769919, client:SolanaLabs) Blockchain, Rebuilt for Scale
USAGE: solana [FLAGS] [OPTIONS] <SUBCOMMAND>
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 --use-quic Use QUIC when sending transactions. --use-udp Use UDP when sending transactions. -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: ~/.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
SUBCOMMANDS: account Show the contents of an account address Get your public key address-lookup-table Address lookup table management airdrop Request SOL from a faucet authorize-nonce-account Assign account authority to a new entity balance Get your balance block Get a confirmed block block-height Get current block height block-production Show information about block production block-time Get estimated production time of a block catchup Wait for a validator to catch up to the cluster close-vote-account Close a vote account and withdraw all funds remaining cluster-date Get current cluster date, computed from genesis creation time and network time cluster-version Get the version of the cluster entrypoint completion Generate completion scripts for various shells config Solana command-line tool configuration settings confirm Confirm transaction by signature create-address-with-seed Generate a derived account address with a seed. For program derived addresses (PDAs), use the find-program-derived-address command instead create-nonce-account Create a nonce account create-stake-account Create a stake account create-stake-account-checked Create a stake account, checking the withdraw authority as a signer create-vote-account Create a vote account deactivate-stake Deactivate the delegated stake from the stake account decode-transaction Decode a serialized transaction delegate-stake Delegate stake to a vote account epoch Get current epoch epoch-info Get information about the current epoch feature Runtime feature management fees Display current cluster fees (Deprecated in v1.8.0) find-program-derived-address Generate a program derived account address with a seed first-available-block Get the first available block in the storage genesis-hash Get the genesis hash gossip Show the current gossip network nodes help Prints this message or the help of the given subcommand(s) inflation Show inflation information largest-accounts Get addresses of largest cluster accounts leader-schedule Display leader schedule live-slots Show information about the current slot progression logs Stream transaction logs merge-stake Merges one stake account into another new-nonce Generate a new nonce, rendering the existing nonce useless nonce Get the current nonce value nonce-account Show the contents of a nonce account ping Submit transactions sequentially program Program management redelegate-stake Redelegate active stake to another vote account rent Calculate rent-exempt-minimum value for a given account data field length. resolve-signer Checks that a signer is valid, and returns its specific path; useful for signers that may be specified generally, eg. usb://ledger sign-offchain-message Sign off-chain message slot Get current slot split-stake Duplicate a stake account, splitting the tokens between the two stake-account Show the contents of a stake account stake-authorize Authorize a new signing keypair for the given stake account stake-authorize-checked Authorize a new signing keypair for the given stake account, checking the authority as a signer stake-history Show the stake history stake-minimum-delegation Get the stake minimum delegation amount stake-set-lockup Set Lockup for the stake account stake-set-lockup-checked Set Lockup for the stake account, checking the new authority as a signer stakes Show stake account information supply Get information about the cluster supply of SOL transaction-count Get current transaction count transaction-history Show historical transactions affecting the given address from newest to oldest transfer Transfer funds between system accounts upgrade-nonce-account One-time idempotent upgrade of legacy nonce versions in order to bump them out of chain blockhash domain. validator-info Publish/get Validator info on Solana validators Show summary information about the current validators verify-offchain-signature Verify off-chain message signature vote-account Show the contents of a vote account vote-authorize-voter Authorize a new vote signing keypair for the given vote account vote-authorize-voter-checked Authorize a new vote signing keypair for the given vote account, checking the new authority as a signer vote-authorize-withdrawer Authorize a new withdraw signing keypair for the given vote account vote-authorize-withdrawer-checked Authorize a new withdraw signing keypair for the given vote account, checking the new authority as a signer vote-update-commission Update the vote account's commission vote-update-validator Update the vote account's validator identity wait-for-max-stake Wait for the max stake of any one node to drop below a percentage of total. withdraw-from-nonce-account Withdraw SOL from the nonce account withdraw-from-vote-account Withdraw lamports from a vote account into a specified account withdraw-stake Withdraw the unstaked SOL from the stake account
pubstructAccount { /// lamports in the account pub lamports: u64, /// data held in this account #[serde(with = "serde_bytes")] pub data: Vec<u8>, /// the program that owns this account. If executable, the program that loads this account. pub owner: Pubkey, /// this account's data contains a loaded program (and is now read-only) pub executable: bool, /// the epoch at which this account will next owe rent pub rent_epoch: Epoch, }
pubstructVersionedTransaction { /// List of signatures #[serde(with = "short_vec")] pub signatures: Vec<Signature>, /// Message to sign. pub message: VersionedMessage, }
从中可以简单理解为,交易就是一连串的交易指令,以及需要签名的指令的签名内容。
交易指令
上面说到的交易指令又是什么呢?先来看下定义:
1 2 3 4 5 6 7 8 9 10
pubstructCompiledInstruction { /// Index into the transaction keys array indicating the program account that executes this instruction. pub program_id_index: u8, /// Ordered indices into the transaction keys array indicating which accounts to pass to the program. #[serde(with = "short_vec")] pub accounts: Vec<u8>, /// The program input data. #[serde(with = "short_vec")] pub data: Vec<u8>, }
pubstructMint { /// Optional authority used to mint new tokens. The mint authority may only be provided during /// mint creation. If no mint authority is present then the mint has a fixed supply and no /// further tokens may be minted. pub mint_authority: COption<Pubkey>, /// Total supply of tokens. pub supply: u64, /// Number of base 10 digits to the right of the decimal place. pub decimals: u8, /// Is `true` if this structure has been initialized pub is_initialized: bool, /// Optional authority to freeze token accounts. pub freeze_authority: COption<Pubkey>, }
pubstructAccount { /// The mint associated with this account pub mint: Pubkey, /// The owner of this account. pub owner: Pubkey, /// The amount of tokens this account holds. pub amount: u64, /// If `delegate` is `Some` then `delegated_amount` represents /// the amount authorized by the delegate pub delegate: COption<Pubkey>, /// The account's state pub state: AccountState, /// If is_native.is_some, this is a native token, and the value logs the rent-exempt reserve. An /// Account is required to be rent-exempt, so the value is used by the Processor to ensure that /// wrapped SOL accounts do not drop below this threshold. pub is_native: COption<u64>, /// The amount delegated pub delegated_amount: u64, /// Optional authority to close the account. pub close_authority: COption<Pubkey>, }
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 newkeypair to /Users/you/.config/solana/id.json // 这里设置好密码后,提示keypair被加密存在存在"/Users/you/.config/solana/id.json"
=========================================================================== pubkey: Czorr4y9oFvE3VdfCLVFuKDYxaNUG1iyQomR7kMZUuzi // public key: 账户公钥 =========================================================================== Save this seed phrase and your BIP39 passphrase to recover your newkeypair: tail ... despair // 创建完成后其对应的BIP39的助记词,这里助记词要记住,后续使用钱包的时候,可以通过助记词来恢复账号。 ===========================================================================
pub struct Account { /// lamports in the account pub lamports: u64, /// data held in this account #[serde(with = "serde_bytes")] pub data: Vec<u8>, /// the program that owns this account. If executable, the program that loads this account. pub owner: Pubkey, /// this account's data contains a loaded program (and is now read-only) pub executable: bool, /// the epoch at which this account will next owe rent pub rent_epoch: Epoch, }
1pub struct Account { 2 /// The mint associated with this account 3 pub mint: Pubkey, 4 /// The owner of this account. 5 pub owner: Pubkey, 6 /// The amount of tokens this account holds. 7 pub amount: u64, 8 /// If `delegate` is `Some` then `delegated_amount` represents 9 /// the amount authorized by the delegate 10 pub delegate: COption<Pubkey>, 11 /// The account's state 12 pub state: AccountState, 13 /// If is_native.is_some, this is a native token, and the value logs the rent-exempt reserve. An 14 /// Account is required to be rent-exempt, so the value is used by the Processor to ensure that 15 /// wrapped SOL accounts do not drop below this threshold. 16 pub is_native: COption<u64>, 17 /// The amount delegated 18 pub delegated_amount: u64, 19 /// Optional authority to close the account. 20 pub close_authority: COption<Pubkey>, 21 }
/** * Transaction Instruction class */ exportclassTransactionInstruction { /** * Public keys to include in this transaction * Boolean represents whether this pubkey needs to sign the transaction */ keys: Array<AccountMeta>; /** * Program Id to execute */ programId: PublicKey; /** * Program input */ data: Buffer; constructor(opts: TransactionInstructionCtorFields); }
其中 programId 表示调用合约的地址。key 是合约中需要使用到的 Account, data 则是所有的输入序列化后的二进制。
因为合约的入口是:
1 2 3 4 5 6 7 8
declare_process_instruction!( process_instruction, DEFAULT_COMPUTE_UNITS, |invoke_context| { let transaction_context = &invoke_context.transaction_context; let instruction_context = transaction_context.get_current_instruction_context()?; let instruction_data = instruction_context.get_instruction_data(); let instruction = limited_deserialize(instruction_data)?;