Skip to content

Instantly share code, notes, and snippets.

@whiteneon
Created April 3, 2022 15:12
Show Gist options
  • Save whiteneon/40a11a2937b53c3d980f34ac9f185f09 to your computer and use it in GitHub Desktop.
Save whiteneon/40a11a2937b53c3d980f34ac9f185f09 to your computer and use it in GitHub Desktop.
Convert Solana CLI Keypair file to Base58 Encoded Private Key for use in Phantom Wallet
#!/usr/bin/python3
#I believe will only work on python3. You need base58 (pip install base58)
#Please note: I'm not a programmer and there are probably more elegant ways to accomplish this, but this does work.
#Usage: Call the script with the keypair file as the first argument.
import base58
import sys
keyfile = sys.argv[1]
file = open(keyfile, 'r')
data = file.read().replace('\n', '').replace('[', '').replace(']', '')
file.close
key = b''
for x in data.split(','):
w = int(x).to_bytes(1,'big')
key = b"".join([key, w])
enc_key = base58.b58encode(key)
print(enc_key)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment