1

I'm performing a call of this CLI function

spl-token balance --token--

So it requires a keypair.json file to be present at this location ~ .config/solana/id.json (for Mac)

Without this file CLI throws an error

error: No such file or directory (os error 2)

Is there a way to specify a path to keypair or even better specify the whole file content (encoded or not) as a CLI param?

BTW this issue is not limited to just this command, most of spl-token cli commands I've tried has this issue.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Vlad Kolbaia
  • 267
  • 4
  • 11

2 Answers2

1

If you want to specify the keypair directly, you can use the --fee-payer argument, ie:

$ spl-token --fee-payer id.json balance --owner <YOUR_PUBKEY> <TOKEN_MINT_PUBKEY>

The --fee-payer argument accepts a few different possibilities, including keypair files, or even keywords that accept input from stdin. More information at https://docs.solana.com/wallet-guide/paper-wallet#hierarchical-derivation

It isn't super intuitive, but the possibility is there. For example, a balance check shouldn't need a signer. PRs / suggestions for improvement are always accepted on GitHub! https://github.com/solana-labs/solana-program-library

Jon C
  • 7,019
  • 10
  • 17
  • Is it possible to supply the `--owner` for `spl-token transfer` as a string (bs58 encoded) instead of a file-path to the disk? – Vlad Kolbaia Feb 04 '22 at 17:53
  • No, because the owner must sign the transaction in order to transfer. Otherwise, you could transfer from anyone else's wallet and into yours! – Jon C Feb 04 '22 at 23:28
  • Yeah, I get that you need the private key to authorize, I am asking if I can provide it as a string instead of the file path. So that I can store it in memory instead of a file on the disk. – Vlad Kolbaia Feb 05 '22 at 12:01
  • Jon, I created an feature request issue https://github.com/solana-labs/solana-program-library/issues/2877 I will be more than happy to work on this if the team decides this is appropriate – Vlad Kolbaia Feb 06 '22 at 06:02
  • 1
    Great, that'll be your best bet, since you're right, you can't provide the keypair as a base58-encoded string. As a workaround, you could use any of the other formats currently supported, such as the secret key seed words, provided via stdin. Your change would start in https://github.com/solana-labs/solana/blob/86c3990c25920d0619beaba213ca8acf284842f4/clap-utils/src/keypair.rs#L752 and https://github.com/solana-labs/solana/blob/86c3990c25920d0619beaba213ca8acf284842f4/clap-utils/src/keypair.rs#L442 to support a new format similar to the `Pubkey` format. – Jon C Feb 06 '22 at 15:25
  • 1
    In our conversation with Trent in the GH issue I linked to it was decided that this is not needed. Anyway thank you for your help. I'm sure when I get more knowledgable about Solana I'll get to contribute something to this great project! – Vlad Kolbaia Feb 11 '22 at 13:40
  • That would be much appreciated -- looking forward to seeing some PRs from you then! – Jon C Feb 11 '22 at 16:54
0

This has always been possible with the prompt:// argument, which enabled paper wallets. For USDC:

spl-token transfer EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v <AMOUNT> <RECIPIENT_ADDRESS> --fund-recipient --allow-unfunded-recipient --owner prompt:// --fee-payer prompt://

You'll then be able to paste the private keys of the owner and the fee payer.

Gascoyne
  • 101
  • 1