Skip to content

Instantly share code, notes, and snippets.

@whiteneon
Created April 3, 2022 15:28
Show Gist options
  • Save whiteneon/3ececd5d5b68ff4d05673c42d57c1270 to your computer and use it in GitHub Desktop.
Save whiteneon/3ececd5d5b68ff4d05673c42d57c1270 to your computer and use it in GitHub Desktop.
Convert Phantom Private Key Export to data for use in Solana CLI Keypair file.
#!/usr/bin/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 filename to store the keypair file as the first argument.
# The private key exported from Phantom Wallet is the second argument.
# I didn't write all this code, 2 main lines including join(map(lambda line were copied from another site,
# credit to original authors.
import base58
import sys
import os.path
key58 = sys.argv[2]
filename = sys.argv[1]
if (os.path.exists(filename)):
print("Filename already exists, please specify a different filename")
exit()
byte_array = base58.b58decode(key58)
json_string = "[" + ",".join(map(lambda b: str(b), byte_array)) + "]"
#print(json_string)
textfile = open(filename, 'w')
n = textfile.write(json_string)
textfile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment