> For the complete documentation index, see [llms.txt](/llms.txt).

# Secp256k1 private key

To retrieve the secp256k1 private key of the user, use `getPrivateKey` method. The method returns an EVM compatible private key which can be used to sign transactions on EVM compatible chains.

note

Web3Auth supports two widely used cryptographic curves, Secp256k1 and Ed25519, making it chain-agnostic and compatible with multiple blockchain networks. [Learn more about how to connect different blockchains](/embedded-wallets/connect-blockchain/).

Session behavior

- After `initialize()` or `connectTo()` completes successfully, `getPrivateKey()` returns the private key.
- If no session has been restored or created on this `Web3Auth` instance, `getPrivateKey()` returns an **empty string** (`""`).
- After `logout()`, or if the session has no key of the requested type, `getPrivateKey()` throws `IllegalStateException` (`No valid private key found`).
- If `useSFAKey = true` in `Web3AuthOptions`, this method returns the SFA core kit key (`coreKitKey`) instead of the standard secp256k1 key.

Track whether the user is signed in from the results of `initialize()`, `connectTo()`, and `logout()`, rather than by probing the key.

## Usage

```kotlin
val initializeCF = web3Auth.initialize()
initializeCF.whenComplete { _, error ->
    if (error == null) {
        // Active session restored
        val privateKey = web3Auth.getPrivateKey()
    } else {
        // No active session, prompt the user to sign in
    }
}

```
