> For the complete documentation index, see [llms.txt](https://docs.tanx.fi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tanx.fi/tech/api-documentation/account/generating-l2-key-pairs.md).

# Generating L2 Key Pairs

This page helps you generate L2 key pairs either through the [tanX website](https://trade.tanx.fi/) or with a code snippet.

\
To obtain the L2 Key Pair, you can proceed with either of the following methods:

1. Once the wallet is connected, obtain the Key Pair from the official [tanX website’s](https://trade.tanx.fi/) Account Settings Tab. Please refer to the image below for further guidance: \
   \
   Navigate to **Settings -> tanX key -> Show Keys** and sign the request to obtain the keys. Copy these keys and securely store them.

<figure><img src="/files/EQ6aKrt4sxYjpcU4ZETQ" alt=""><figcaption></figcaption></figure>

2. Generate the L2 key pair using the [tanX Node.js SDK](https://www.npmjs.com/package/@tanx-libs/tanx-connector):

```javascript
import { generateKeyPairFromEthPrivateKey } from '@tanx-libs/tanx-connector'

const keypair = generateKeyPairFromEthPrivateKey(ethPrivateKey, 'testnet') // default is mainnet
const stark_public_key = keypair.getPublic().getX().toString('hex') 
const stark_private_key = keypair.getPrivate().toString('hex')
```

This code snippet demonstrates how to generate L2 key pairs programmatically using the [tanX Node.js SDK](https://www.npmjs.com/package/@tanx-libs/tanx-connector).
