Skip to content

Instantly share code, notes, and snippets.

@tracy-codes
Created September 29, 2022 21:03
Show Gist options
  • Save tracy-codes/f17e7ed8acfdd1be442f632f5b80763c to your computer and use it in GitHub Desktop.
Save tracy-codes/f17e7ed8acfdd1be442f632f5b80763c to your computer and use it in GitHub Desktop.
Convert Solana Private Key to base58 Keypair Array
// npm install bs58
import bs58 from 'bs58';
import fs from 'fs';
import path from 'path';
// Replace with the private key string that was exported from your solana wallet provider (phantom, etc)
const privateKey = "abc123456def";
// bs58.decode will return a ByteArray.
const keypairFileData = bs58.decode(privateKey);
fs.writeFileSync(path.join(__dirname, 'new-keypair.json'), JSON.stringify(keypairFileData));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment