---
title: How to Restore a Keypair or Signer
description: "Learn how to restore keypairs from a secret key on Solana."
---

If you have an existing secret key, you can restore your Keypair from it. This
allows you to access your wallet and sign transactions in your dApp.

<Callout type="warn">
  Handle secret keys with care: never embed them in client-side code or commit
  them to source control. For backend services in production, use a
  key-management backend instead of a raw secret key — see [Signing in
  Production](/docs/core/transactions/signing-in-production).
</Callout>

## From Bytes

<CodeTabs storage="cookbook" flags="r">

```ts !! title="Kit" file=packages/docs-examples/cookbook/wallets/restore-keypair/from-bytes-kit.ts#region=from-bytes

```

```ts !! title="Legacy" file=packages/docs-examples/cookbook/wallets/restore-keypair/from-bytes-legacy.ts#region=from-bytes

```

```rust !! title="Rust" file=packages/docs-examples/cookbook/wallets/restore-keypair/rust/src/bin/from-bytes.rs#region=from-bytes

```

</CodeTabs>

## From Base58 String

<CodeTabs storage="cookbook" flags="r">

```ts !! title="Kit" file=packages/docs-examples/cookbook/wallets/restore-keypair/from-base58-kit.ts#region=from-base58

```

```ts !! title="Legacy" file=packages/docs-examples/cookbook/wallets/restore-keypair/from-base58-legacy.ts#region=from-base58

```

```rust !! title="Rust" file=packages/docs-examples/cookbook/wallets/restore-keypair/rust/src/bin/from-base58.rs#region=from-base58

```

```py !! title="Python"
from solders.keypair import Keypair

def main():
    keypair_bytes = bytes([
        174, 47, 154, 16, 202, 193, 206, 113, 199, 190, 53, 133, 169, 175, 31, 56,
        222, 53, 138, 189, 224, 216, 117, 173, 10, 149, 53, 45, 73, 251, 237, 246, 15,
        185, 186, 82, 177, 240, 148, 69, 241, 227, 167, 80, 141, 89, 240, 121, 121,
        35, 172, 247, 68, 251, 226, 218, 48, 63, 176, 109, 168, 89, 238, 135
    ])

    signer = Keypair.from_bytes(keypair_bytes)
    print(signer.pubkey())

if __name__ == "__main__":
    main()
```

</CodeTabs>
