Most users interact with apps via their favorite Stacks wallet.
Developers can build web apps that prompt the user for an action (e.g. sign a transaction), and then the wallet will handle the rest.
Let's start by generating a random private key.
Note that this will return a different value each time you run the code.
import { randomPrivateKey } from '@stacks/transactions';const privateKey = randomPrivateKey();// 'f5a31c1268a1e37d4edaa05c7d11183c5fbfdcdc48aae36ea4d8cd5cb709932801'
Private keys are typically represented as hex strings in Stacks.js.
For more control you can use the PrivateKey type, which also accepts raw bytes as Uint8Array in JavaScript.