solana-labs / solana-web3.js

Solana JavaScript SDK
https://solana-labs.github.io/solana-web3.js
MIT License
2.09k stars 840 forks source link

Helper method to load keypair from paper wallet #1607

Open jim4067 opened 12 months ago

jim4067 commented 12 months ago

Motivation

1562

solana paper wallets are stored in ~/.config/solana/id.json. Everytime I need to use the wallet I have to either declare the keypair in my project or create a helper function that loads the keypair from the path.

const USER_KEYPAIR_PATH = homedir() + "/.config/solana/id.json";
export const signerKeypair = Keypair.fromSecretKey(
    Buffer.from(JSON.parse(readFileSync(USER_KEYPAIR_PATH, "utf-8")))
);

Example use case

When working and you need a signer that does not change and you do not want to have to declare the keypair in your config files,

having a function like loadFromFilePath(path: string) might be nice

Details

Could be implemented in the Keypair interface.

have a function loadFromFilePath(path: string?) for this that optionally takes in a path argument since the default Solana config location for a wallet is config/solana/id.json else if the user supplies an argument to this function load the wallet from the supplied location.

buffalojoec commented 11 months ago

Hey, check out this repo!

https://github.com/solana-developers/node-helpers