How to get private key (sui address ) importable to Sui wallet from a Sui keystore

I have a sui keystore generated using sui client CLI. I found this:

    let secretKey = raw.slice(1);
    let keypair = Ed25519Keypair.fromSecretKey(secretKey);

    console.log(`keypair: ${keypair.getKeyScheme()}`)
    console.log(`publicKey: ${keypair.getPublicKey().toSuiAddress()}`)
    console.log(`privateKey: ${keypair.export().privateKey}`);

The console output looks like this:

keypair: ED25519
publicKey: 0xba84193***9ed
privateKey: L4tOBF****ZyPplG9s=

when I tried to create a new wallet in Sui Wallet by importing using the above private key, it failed with an invalid format.
It seems that the SDK provides the toSuiAddress API for the public key, but not for the private key.

Is it possible to use the Sui keystore to generate the private key usable in the Sui wallet? My end goal is to use the same admin wallet that publishes the package to test my contract in the sui explorer. The first time I generated the address I was not aware of the seed phrase shown in the console.


In order to get the private key ready to be imported into SUI wallet you can use the command:
sui client convert <PRIVATE_KEY>
where <PRIVATE_KEY> is the key stored inside ~/.sui/sui_config/sui.keystore

Note that SUI wallet only supports ed25519 encryption scheme, so that address should have been created using this algorithm, otherwise it cannot be used by SUI wallet.

1 Like

The command: sui client convert does not exist. I am using sui 1.5.0-c9b896c0b

I am sorry, I meant sui keytool convert.

1 Like