435 stable releases

new 2.1.6 Dec 15, 2024
2.1.4 Nov 27, 2024
2.0.3 Jul 20, 2024
1.18.26 Oct 11, 2024
0.23.8 Feb 29, 2020

#160 in Magic Beans

Download history 10375/week @ 2024-08-26 8587/week @ 2024-09-02 7262/week @ 2024-09-09 6060/week @ 2024-09-16 7140/week @ 2024-09-23 8450/week @ 2024-09-30 7401/week @ 2024-10-07 8448/week @ 2024-10-14 8465/week @ 2024-10-21 10293/week @ 2024-10-28 8622/week @ 2024-11-04 7414/week @ 2024-11-11 9351/week @ 2024-11-18 9225/week @ 2024-11-25 9965/week @ 2024-12-02 10199/week @ 2024-12-09

39,441 downloads per month
Used in 162 crates (76 directly)

Apache-2.0

510KB
10K SLoC

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

~19–31MB
~498K SLoC