Skip to content

Instantly share code, notes, and snippets.

@AlmostEfficient
Last active April 28, 2024 09:31
Show Gist options
  • Save AlmostEfficient/f4fec77492a7e8dad81df9707932234f to your computer and use it in GitHub Desktop.
Save AlmostEfficient/f4fec77492a7e8dad81df9707932234f to your computer and use it in GitHub Desktop.
Load a Solana keypair from a .env file as a byte array
// "@solana/web3.js": "^1.87.6",
import { Connection, Keypair, clusterApiUrl } from '@solana/web3.js';
import dotenv from 'dotenv';
dotenv.config();
const connection = new Connection(clusterApiUrl('devnet'), 'confirmed');
const payerSecretKey = JSON.parse(process.env.PAYER);
const payer = Keypair.fromSecretKey(Uint8Array.from(payerSecretKey));
if (!payer) {
throw new Error('PAYER is not set')
}
console.log('Payer address:', payer.publicKey.toBase58());
console.log("Payer Account Balance:", await connection.getBalance(payer.publicKey));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment