rustsmartcontractssolanawallet

How to get a private key from seed phrase on solana?


I stored public key and seed phrase in safe place, but not the private key. When I add my wallet on phantom, it asks to add private key instead of seed phrase. Any solutions? Thank you.


Solution

  • Solution 1: navigate to the keypair json on your system. i.e. .config/solana/id.json. Then you can find out the array for the private key.

    Solution 2: you can use solana web3 SDK.

      let seed = Uint8Array.from(
        SEED_STRING.split(",")
      ).slice(0, 32);
    
      // create keypairs
      let KEYPAIRS = web3.Keypair.fromSeed(seed);
      console.log(KEYPAIRS.privateKey);