Method Signature
align.blockchain.wallets.createFromPrivateKey(
privateKey: string
): Promise<Wallet>
Parameters
The private key string (with or without 0x prefix)
Returns
The wallet’s public address
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}`);
const wallet = await align.blockchain.wallets.createFromPrivateKey(
process.env.PRIVATE_KEY
);
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.