3

I'm currently writing the CLI for the Squads Protocol v4 program in Rust and would like to add support for Ledger signing. Right now, on CLI tx execution, you can specify a keypair directory of who the signer of a transaction is, just like it is for the solana cli.

I've stumbled upon these docs(https://docs.solana.com/wallet-guide/hardware-wallets) and it seems that Ledger is supported in the solana cli by specifying "usb://[/<WALLET_ID>][?key=<DERIVATION_PATH>]" as the keypair path.

I'd want to know if there are any resources/references or crates I could look at to add Ledger support to our CLI as well, best would be in the same format as the Solana CLI.

Thanks in advance for the help.

1

1 Answer 1

2

This has actually been pretty easy, there is a crate called "solana_clap_v3_utils" with a function called "signer_from_path".

You can then just invoke this function with the same keypair path format as you would with the regular Solana CLI (meaning that Ledger is supported). This will then return a "dyn Signer" Box which you can use to sign transactions.

Here is a code example:

use clap_v3::ArgMatches;
use solana_clap_v3_utils::keypair::signer_from_path;
use solana_sdk::signer::Signer;


pub fn create_signer_from_path(
    keypair_path: String,
) -> Result<Box<dyn Signer>, Box<dyn std::error::Error>> {
    let mut wallet_manager = None;
    let matches = ArgMatches::default();


    signer_from_path(&matches, &keypair_path, "Keypair", &mut wallet_manager)
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.