> For the complete documentation index, see [llms.txt](https://fone-network.gitbook.io/whitepaper/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://fone-network.gitbook.io/whitepaper/fone-network-whitepaper/wallet-creation.md).

# Wallet Creation

**Wallet Creation**

The wallet creation process involves generating a new key pair, which gives us both a **public address** and a **private key**. Here’s the code and a breakdown of how it works:

```javascript
let key, address, fullAddress, privateKey;

do {
    key = ec.genKeyPair();  // Generate a new key pair
    fullAddress = key.getPublic('hex');  // Get the full public address in hexadecimal
    address = key.getPublic().getX();  // Get the 'X' coordinate of the public key as the main address
    privateKey = key.getPrivate('hex');  // Get the private key in hexadecimal format
} while (!address.toString(16).startsWith('f'));  // Ensure the address starts with 'f'
```

**How It Works**

* Generate Key Pair: The ec.genKeyPair() function creates a new elliptic curve key pair. This includes a public key (for the address) and a private key.
* Get Public Address: getPublic('hex') provides the full public key in hexadecimal format, which serves as the unique wallet address.
* Address Validation: To maintain consistency, we ensure each address starts with the letter ‘f’. If the generated address does not begin with ‘f’, we discard it and generate a new one. This is done using a do...while loop.
* Get Private Key: Finally, getPrivate('hex') retrieves the private key in hexadecimal format. This key is essential for wallet recovery and must be kept secure.

*Example Creation*

```json
{
    "fullAddress": "048fcd... (full address here)",
    "address": "f8b7a...",
    "privateKey": "d1b1c... (private key here)"
}
```

{% hint style="danger" %}
Security Tip: Always store your private key securely and never share it with anyone. The private key is the only way to access your wallet, so it should be kept safe.
{% endhint %}
