400 stable releases

new 1.18.16 Jun 7, 2024
1.18.12 Apr 26, 2024
1.18.9 Mar 29, 2024
1.17.13 Dec 21, 2023
0.23.8 Feb 29, 2020

#1335 in Magic Beans

Download history 6673/week @ 2024-02-15 7533/week @ 2024-02-22 9239/week @ 2024-02-29 10050/week @ 2024-03-07 11232/week @ 2024-03-14 8422/week @ 2024-03-21 15976/week @ 2024-03-28 56778/week @ 2024-04-04 16334/week @ 2024-04-11 9318/week @ 2024-04-18 9752/week @ 2024-04-25 8309/week @ 2024-05-02 8969/week @ 2024-05-09 8730/week @ 2024-05-16 7255/week @ 2024-05-23 7434/week @ 2024-05-30

34,005 downloads per month
Used in 145 crates (62 directly)

Apache-2.0

640KB
13K SLoC

Rust 12K SLoC // 0.0% comments Bitbake 1K SLoC // 0.2% comments Shell 440 SLoC // 0.1% comments

Loading and saving the Solana CLI configuration file.

The configuration file used by the Solana CLI includes information about the RPC node to connect to, the path to the user's signing source, and more. Other software than the Solana CLI may wish to access the same configuration and signer.

The default path to the configuration file can be retrieved from CONFIG_FILE, which is a lazy_static of Option<String>, the value of which is

~/.config/solana/cli/config.yml

CONFIG_FILE will only be None if it is unable to identify the user's home directory, which should not happen under typical OS environments.

The CLI configuration is defined by the Config struct, and its value is loaded with Config::load and saved with Config::save.

Two important fields of Config are

  • json_rpc_url, the URL to pass to solana_rpc_client::rpc_client::RpcClient.
  • keypair_path, a signing source, which may be a keypair file, but may also represent several other types of signers, as described in the documentation for solana_clap_utils::keypair::signer_from_path.

Examples

Loading and saving the configuration. Note that this uses the anyhow crate for error handling.

use anyhow::anyhow;
use solana_cli_config::{CONFIG_FILE, Config};

let config_file = solana_cli_config::CONFIG_FILE.as_ref()
    .ok_or_else(|| anyhow!("unable to get config file path"))?;
let mut cli_config = Config::load(&config_file)?;
// Set the RPC URL to devnet
cli_config.json_rpc_url = "https://api.devnet.solana.com".to_string();
cli_config.save(&config_file)?;

Dependencies

~21–32MB
~556K SLoC