# 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="https://3437812349-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzLrVMuCawk9OpwBGSbAw%2Fuploads%2F1l9DByKx5wkDZVr03RQ9%2Ftanx-key.png?alt=media&#x26;token=fc03de33-cd3f-4d9e-a1f0-4a313c487a83" 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).
