Problem generating the wallet with RawKey ()

Are we able to create wallet from privatekey exported with TerraStation?
The following code throws an error complaining about the private key:
Error: Expected private key to be an Uint8Array with length 32

import { LCDClient, MnemonicKey, RawKey } from ‘@terra-money/terra.js’

const terra = new LCDClient({
URL: ‘’,
chainId: ‘columbus-4’

const wallet = terra.wallet(
new RawKey(

1 Like

Buffer.from uses UTF-8 encodings by default, while private keys usually use hex or base64.


Buffer.from("yourPrivateKey", "hex")
// or
Buffer.from("yourPrivateKey", "base64")
1 Like

It seems that terra.js doesn’t support private key exported from Terra Station where a password is required

1 Like

Alright, I figured it out

import * as CryptoJS from "crypto-js";
import { LCDClient, MnemonicKey, RawKey } from "@terra-money/terra.js";

const terra = new LCDClient({
  chainID: "columbus-5",
  URL: "",

First, I generate a mnemonic phrase and create a wallet from it using terra.js. I take a note of what the wallet address:

const wallet1 = terra.wallet(
  new MnemonicKey({
      "satisfy adjust timber high purchase tuition stool faith fine install that you unaware feed domain license impose boss human eager hat rent enjoy dawn",



Now I put the same mnemonic phrase into Terra Station, export wallet, decrypt the exported private key, and create a wallet using the decrypted key with terra.js. If everything works it should give me the same wallet address as above.

function decrypt(transitmessage: string, pass: string) {
  const salt = CryptoJS.enc.Hex.parse(transitmessage.substr(0, 32));
  const iv = CryptoJS.enc.Hex.parse(transitmessage.substr(32, 32));
  const encrypted = transitmessage.substring(64);

  const keySize = 256;
  const iterations = 100;
  const key = CryptoJS.PBKDF2(pass, salt, {
    keySize: keySize / 32,
    iterations: iterations,

  return CryptoJS.AES.decrypt(encrypted, key, {
    iv: iv,
    padding: CryptoJS.pad.Pkcs7,
    mode: CryptoJS.mode.CBC,
type ExportedWallet = {
  name: string;
  address: string;
  encrypted_key: string;

const exportedWallet: ExportedWallet = JSON.parse(
const decryptedKey = decrypt(exportedWallet.encrypted_key, "localterra");
const wallet2 = terra.wallet(new RawKey(Buffer.from(decryptedKey, "hex")));


1 Like

thanks so much for the code. it worked great!

1 Like

hello guys, I have the same warning when try to transfer or swap, and dont know anythng about the codes, please help me


Thank you for your Post.

Is it Okay for “localterra” as argument even on mainnet?

My private Key isn’t work for this.

Error with below message:
Expected private key to be an Uint8Array with length 32

1 Like

in thie example, localterra is the password used to encrypt the key in Terra Station

1 Like

Please can you guide me.
My terra station wallet does not allow me to transfer my funds to any other wallet or exchange.
Can you help me with this.
I will thank you.

1 Like