# 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).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.tanx.fi/tech/api-documentation/account/generating-l2-key-pairs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
