# Generate a wallet

{% code fullWidth="false" expandable="true" %}

```typescript
import { generateWallet, generateSecretKey } from '@stacks/wallet-sdk';
import { privateKeyToAddress } from '@stacks/transactions'

// Generate a new wallet with a new 24-word seed phrase
const secretKey = generateSecretKey(256); // 256 bits = 24 words
const wallet = await generateWallet({
  secretKey,
  password: 'your-secure-password',
});

// Access the first account
const account = wallet.accounts[0];
const mainnetAddress = privateKeyToAddress(account.stxPrivateKey, 'mainnet');
console.log('Mnemonic:', secretKey);
console.log('Address:', mainnetAddress
```

{% endcode %}

### Description

Create a new wallet with mnemonic phrase or restore from existing seed

### Use Cases

* Creating new wallets for users
* Restoring wallets from seed phrases
* Generating deterministic wallet addresses
* Building wallet applications

### Key Concepts

* **Secret key** - Can be a mnemonic phrase or private key
* **Password** - Encrypts the wallet (different from mnemonic passphrase)
* **Accounts** - Multiple accounts can be derived from one seed
* Wallet SDK generates hierarchical deterministic (HD) wallets following BIP32/BIP39 standards


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.stacks.co/cookbook/stacks.js/accounts-and-addresses/generate-a-wallet.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
