Created
November 12, 2024 12:21
-
-
Save AlperRehaYAZGAN/94bc161d0e5e9e223cc0158589fe1bb7 to your computer and use it in GitHub Desktop.
A simple phantom wallet base58 private key text to json convertor.
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
/* | |
"dependencies": { | |
"@solana/web3.js": "^1.95.4", | |
"bip39": "^3.1.0", | |
"bs58": "^6.0.0" | |
} | |
*/ | |
const bs58 = require("bs58"); | |
const { Keypair } = require("@solana/web3.js"); | |
const privateKey = process.env.KEY || ""; | |
const keypairData = Keypair.fromSeed( | |
Uint8Array.from(bs58.default.decode(privateKey).slice(0, 32)) | |
); | |
console.log("Secret Key:", keypairData.secretKey.toString()); | |
// writ eto file | |
const fs = require("fs"); | |
fs.writeFileSync( | |
"keypair.json", | |
JSON.stringify(Array.from(keypairData.secretKey)) | |
); | |
// to mnemonics | |
const bip39 = require("bip39"); | |
const mnemonic = bip39.entropyToMnemonic( | |
bs58.default.decode(privateKey).slice(0, 32) | |
); | |
console.log("Mnemonic:", mnemonic); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment