Skip to content

Instantly share code, notes, and snippets.

@nissan
Created October 9, 2024 06:53
Show Gist options
  • Save nissan/e771cf313e8ca6eaa54c58a3ba09fb2f to your computer and use it in GitHub Desktop.
Save nissan/e771cf313e8ca6eaa54c58a3ba09fb2f to your computer and use it in GitHub Desktop.
Convert Phantom BS58 private key format to Solana byte array
import bs58 from 'bs58';
import promptSync from 'prompt-sync';
// Initialize prompt
const prompt = promptSync();
// Prompt the user for the base58 private key
const privateKeyBase58 = prompt('Enter your base58-encoded private key: ');
// Decode the base58-encoded private key from Phantom
const decodedKey = bs58.decode(privateKeyBase58);
// Convert the decoded key into a Uint8Array
const uint8ArrayKey = new Uint8Array(decodedKey.buffer, decodedKey.byteOffset, decodedKey.byteLength / Uint8Array.BYTES_PER_ELEMENT);
// Output the key as a JSON array to the console
console.log('Decoded Private Key:', JSON.stringify(Array.from(uint8ArrayKey)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment