Accounts
Key derivation and account creation for signing transactions.
From Private Key
import { privateKeyToAccount } from "@secondlayer/stacks/accounts";
const account = privateKeyToAccount("0xprivatekey...");
account.address; // "SP2J6..."
account.publicKey; // "03ab..."
account.sign(hash); // Uint8ArrayFrom Mnemonic
import { mnemonicToAccount } from "@secondlayer/stacks/accounts";
const account = mnemonicToAccount("abandon abandon abandon ...");
// Derive a different account index
const account2 = mnemonicToAccount("abandon ...", { accountIndex: 1 });Custom Signer
import { toAccount } from "@secondlayer/stacks/accounts";
const account = toAccount({
address: "SP2J6...",
publicKey: "03ab...",
sign: async (hash) => {
// custom signing logic (HSM, hardware wallet, etc.)
return signature;
},
});Browser Wallet
import { providerToAccount } from "@secondlayer/stacks/accounts";
const account = providerToAccount(window.StacksProvider);