Importing a Local Sui Address into your Web Sui Wallet
April 15th, 2023

With the help of the Sui keytool utility and a few basic linux commands, we can import a locally created Sui Account into the Sui Wallet.

Since the private key stored locally is formatted as base64 and the Sui Wallet PK is an hex string, we will have to do some here. No worries, I’ve got you covered here.

Importing a locally created private key (with the sui client) into the Sui Wallet.
Importing a locally created private key (with the sui client) into the Sui Wallet.
sui keytool -h

List addresses and their respective key pairs:

sui keytool list
# Result: Sui addresses, public keys, and schemes

Since the Sui Wallet only accepts importing private keys generated with the ed25519 algorithm, let’s create a new address and go through all the steps to import it on the web wallet:

sui client new-address ed25519
# Result: a new address is created and the seed phrase is printed

Private keys created locally by the sui client are stored in the sui.keystore file and encoded as base64.

cat ~/.sui/sui_config/sui.keystore
# Result: list of private keys formatted in base64

Given a private key in the list, we can find the corresponding public key (or account / address) using the sui toolkit:

sui keytool unpack YOUR_PRIVATE_KEY_HERE
# Result: a file is create in the current dir containing the
# corresponding public key (address) and private key

Now let’s decode the base64 private key saved in the sui.keystore file. According to the documentation, the pk in base64 “YOUR_PRIVATE_KEY_HERE” is 33 bytes long, being:

  • First byte: flag indicating the cryptographic algorithm used to create the key: 0 means ed25519, while 1 means secp256k1.

  • Remaining 32 bytes: private key

Let’s decode the base64 string into an hexadecimal string:

echo "YOUR_PRIVATE_KEY_HERE" | base64 -d | od -t x1 -An

# Result: string decoded into an hex string showed byte by byte
# Fictitious data:
0a 44 66 88 cc ff ae fa 26 fa 15 cc 59 21 15 10
1f 1a ba a1 11 a7 36 71 2d 10 13 11 00 1e 91 41
2a

We discard the first byte 00 and now have our pk in hex (let’s remove spaces):

echo "YOUR_PRIVATE_KEY_HERE" | base64 -d | od -t x1 -An | tr -d ' '
# Result: pk decoded into an hex string without spaces
# Fictitious data:
0001234567890abcdef0123456789abcdef0123456789abcdef012346578901231

Remove the first two zeros (ed25519 schema):

# Fictitious data
01234567890abcdef0123456789abcdef0123456789abcdef012346578901231

Now, remember:

From the Sui keytool we had the public address and now, after making some base64 decoding, we have the private key in the right format for the Sui Wallet.

**Go to the Sui Wallet (if you dont have it, install it here), in the “Import Existing Account” enter the derived private key. **

Voilà!!! Confirm that the address showing in the wallet corresponds to the public key in your local machine.

If you liked the content, collect and subscribe ☕️ Thank you!!

About me 🐒 Crypto Sapiens, Dev, Writer, Creator, Manager, Engineer, and many other things. Love reading and learning multiple languages en pt de fr it

Location 📍 In a block ⛓️ mined a long time ago

@trekker_crypto 🐦️

Subscribe to Crypto Trekker
Receive the latest updates directly to your inbox.
Mint this entry as an NFT to add it to your collection.
Verification
This entry has been permanently stored onchain and signed by its creator.
More from Crypto Trekker

Skeleton

Skeleton

Skeleton