solana_clap_utils::keypair

Function keypair_from_path

Source
pub fn keypair_from_path(
    matches: &ArgMatches<'_>,
    path: &str,
    keypair_name: &str,
    confirm_pubkey: bool,
) -> Result<Keypair, Box<dyn Error>>
Expand description

Loads a Keypair from one of several possible sources.

The path is not strictly a file system path, but is interpreted as various types of signing source, depending on its format, one of which is a path to a keypair file. Some sources may require user interaction in the course of calling this function.

This is the same as signer_from_path except that it only supports signing sources that can result in a Keypair: prompt for seed phrase, keypair file, and stdin.

If confirm_pubkey is true then after deriving the pubkey, the user will be prompted to confirm that the pubkey is as expected.

See signer_from_path for full documentation of how this function interprets its arguments.

ยงExamples

use clap::{App, Arg, value_t_or_exit};
use solana_clap_utils::keypair::keypair_from_path;

let clap_app = App::new("my-program")
    // The argument we'll parse as a signer "path"
    .arg(Arg::with_name("keypair")
        .required(true)
        .help("The default signer"));

let clap_matches = clap_app.get_matches();
let keypair_str = value_t_or_exit!(clap_matches, "keypair", String);

let signer = keypair_from_path(
    &clap_matches,
    &keypair_str,
    "keypair",
    false,
)?;