Skip to content

Instantly share code, notes, and snippets.

@jdaviderb
Forked from Xavier59/privatekeysolana.js
Created October 2, 2022 00:55
Show Gist options
  • Select an option

  • Save jdaviderb/17c3a82732277ccb42b0d6e2dd60c549 to your computer and use it in GitHub Desktop.

Select an option

Save jdaviderb/17c3a82732277ccb42b0d6e2dd60c549 to your computer and use it in GitHub Desktop.

Revisions

  1. @Xavier59 Xavier59 created this gist Dec 28, 2021.
    15 changes: 15 additions & 0 deletions privatekeysolana.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    // exporting from a bs58 private key to an Uint8Array
    // == from phantom private key to solana cli id.json key file
    // npm install bs58 @solana/web3.js

    const web3 = require("@solana/web3.js");
    const bs58 = require('bs58');
    let secretKey = bs58.decode("[base58 private key here]");
    console.log(`[${web3.Keypair.fromSecretKey(secretKey).secretKey}]`);

    // exporting back from Uint8Array to bs58 private key
    // == from solana cli id.json key file to phantom private key

    const bs58 = require('bs58');
    privkey = new Uint8Array([111, 43, 24, ...]); // content of id.json here
    console.log(bs58.encode(privkey));