Skip to main content

Method Signature

align.blockchain.wallets.createFromPrivateKey(
  privateKey: string
): Promise<Wallet>

Parameters

privateKey
string
required
The private key string (with or without 0x prefix)

Returns

address
string
The wallet’s public address
privateKey
string
The wallet’s private key

Examples

import Align from "@tolbel/align";

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

const privateKey = "0x4c0883a69102937d6231471b5dbb628..." // Full 66-char key

const wallet = await align.blockchain.wallets.createFromPrivateKey(privateKey);

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

From Environment Variable

// Recommended: load from secure environment
const wallet = await align.blockchain.wallets.createFromPrivateKey(
  process.env.WALLET_PRIVATE_KEY!
);

// Send a transaction
const tx = await align.blockchain.transactions.sendNativeToken(
  wallet,
  "0xRecipient...",
  "0.1",
  "polygon"
);

Error Handling

import { AlignValidationError } from "@tolbel/align";

try {
  const wallet = await align.blockchain.wallets.createFromPrivateKey(
    "invalid-key"
  );
} catch (error) {
  if (error instanceof AlignValidationError) {
    console.error("Invalid private key format");
  }
}
Never expose private keys in client-side code! Always use server-side operations or secure key management services.