Last active
April 28, 2024 09:31
-
-
Save AlmostEfficient/f4fec77492a7e8dad81df9707932234f to your computer and use it in GitHub Desktop.
Load a Solana keypair from a .env file as a byte array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// "@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