Skip to main content

Method Signature

align.blockchain.wallets.decryptWallet(
  encrypted: EncryptedWallet,
  password: string
): Promise<Wallet>

Parameters

encrypted
EncryptedWallet
required
The encrypted wallet data object
password
string
required
The password used for encryption

Returns

Returns the full Wallet object with address, private key, and mnemonic.

Examples

import Align from "@tolbel/align";
import fs from "fs";

const align = new Align({
  apiKey: process.env.ALIGN_API_KEY!,
  environment: "sandbox",
});

// Load encrypted wallet from storage
const encryptedJson = fs.readFileSync("./wallet.json", "utf8");
const encrypted = JSON.parse(encryptedJson);

// Decrypt the wallet
const wallet = await align.blockchain.wallets.decryptWallet(
  encrypted,
  process.env.WALLET_PASSWORD!
);

console.log(`Decrypted: ${wallet.address}`);

// Now you can use the wallet normally
const tx = await align.blockchain.wallets.sendNativeToken(
  wallet,
  recipient,
  "0.1",
  "polygon"
);
Decryption will fail if the wrong password is provided. Handle errors appropriately.