> 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-import.md).

# Wallet Import

**Wallet Import**

If you already have a private key, you can import it to recover your wallet address.

Here’s the code for the import process:

<pre class="language-javascript"><code class="lang-javascript"><strong>let privateKey;
</strong><strong>
</strong><strong>try {
</strong>    const wallet = ec.keyFromPrivate(privateKey);  // Initialize wallet with the private key
    const address = wallet.getPublic().getX().toString(16);  // Derive the address
    const fullAddress = wallet.getPublic('hex');  // Get the full address in hexadecimal

    // Verify if the address starts with 'f'
    if (!address.startsWith('f')) {
        return res.status(400).json({ error: 'Incompatible wallet address, please check the private key and try again' });
    }
} catch (error) {
    res.status(500).json({ error: 'Error importing wallet' });
}
</code></pre>

**How It Works**

* Input Validation: We first validate the input to ensure the provided private key meets the required criteria.
* Key Derivation: We reconstruct the wallet using the private key. The keyFromPrivate(privateKey) function regenerates the key pair from the given private key.
* Public Address Check: We validate the derived address by checking that it starts with ‘f’. This ensures the wallet is compatible with our network.
* Error Handling: We return an error if the private key is invalid or doesn’t yield a compatible address. If successful, the address and full address are returned.

{% 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 %}
