Skip to content

Instantly share code, notes, and snippets.

@kevinrodriguez-io
Created April 7, 2022 03:24
Show Gist options
  • Save kevinrodriguez-io/02da537f60b1408688b73d489e596300 to your computer and use it in GitHub Desktop.
Save kevinrodriguez-io/02da537f60b1408688b73d489e596300 to your computer and use it in GitHub Desktop.
Get Solana Anchor Wallet From File System
import * as anchor from "@project-serum/anchor";
import fs from "fs/promises";
export const getWallet = async (keyPairFile: string) => {
const payer = anchor.web3.Keypair.fromSecretKey(
Buffer.from(
JSON.parse(
await fs.readFile(keyPairFile, {
encoding: "utf-8",
})
)
)
);
return new anchor.Wallet(payer);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment