> ## Documentation Index
> Fetch the complete documentation index at: https://solana.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# How to Generate Mnemonics for Keypairs

> Mnemonics make it easy for users to store their keypair's secret. Learn how to use mnemonics on Solana.

One way to generate a Keypair is through the use of a Mnemonic. Mnemonics are
generally used to make the user experience within wallets better than a Keypair
file by using a list of readable words (instead of a shorter string of random
numbers and letters).

<CodeGroup>

```ts Typescript
import * as bip39 from "bip39";

const mnemonic = bip39.generateMnemonic();
console.log(mnemonic);
```

```rust Rust
use anyhow::Result;
// https://crates.io/crates/tiny-bip39
use bip39::{Language, Mnemonic, MnemonicType};

fn main() -> Result<()> {
    let mnemonic = Mnemonic::new(MnemonicType::Words12, Language::English);
    let phrase = mnemonic.phrase();

    println!("phrase: {}", phrase);
    Ok(())
}
```

```py Python
from mnemonic import Mnemonic

mnemonic = Mnemonic("english").generate()
print(mnemonic)
```

```go Go
package main

import (
	"fmt"

	"github.com/solana-foundation/solana-go/v2/bip39"
)

func main() {
	entropy, err := bip39.NewEntropy(128) // 12 words
	if err != nil {
		panic(err)
	}
	mnemonic, err := bip39.NewMnemonic(entropy)
	if err != nil {
		panic(err)
	}

	fmt.Println(mnemonic)
}
```

</CodeGroup>

Each call returns a new random 12-word phrase. Anyone who has the phrase can
derive every keypair from it, so keep it secret, and never use a phrase you
found in an example, a tutorial, or a screenshot for a real wallet.
