> ## Documentation Index
> Fetch the complete documentation index at: https://solana.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# Wallets & signatures

> A Solana wallet is an Ed25519 keypair: a public address that anyone can pay, and a private key that signs transactions and messages.

## In short

A wallet holds a key pair: a public *address* that anyone can pay, and a private key that *signs* approvals and never leaves the device.

<div className="sol-usedin not-prose" data-concept="wallet">
<span className="sol-usedin-label">You've used this in:</span> [Quickstart <span className="sol-usedin-step">Step 1</span>](/developers/docs/quickstart/check-balance) [Payments <span className="sol-usedin-step">Overview</span>](/developers/docs/payments/checkout) [Payments <span className="sol-usedin-step">Step 1</span>](/developers/docs/payments/checkout/try-it) [Payments <span className="sol-usedin-step">Step 2</span>](/developers/docs/payments/checkout/browser) [Pay-per-call <span className="sol-usedin-step">Step 1</span>](/developers/docs/payments/paywall-api/try-it)
</div>

## Addresses and private keys

A keypair has two halves:

- **The public key** is the wallet's **address**. It is 32 bytes, written as a
  base58 string of 32 to 44 characters, for example
  `DxQ6RYwhfmX66AQCf3B8aL4P9EivuXnf8HQBkFZwZZFJ`. You can share it freely:
  people pay it, and anyone can look up the
  <span className="sol-chip" data-concept="account"><Tooltip headline="Accounts" tip="Everything on Solana (balances, tokens, programs, app data) lives in accounts: records at an address, each with an owner that is allowed to change it." cta="Learn more" href="/developers/docs/core/accounts">accounts</Tooltip><span className="nojs-only"> ([Accounts](/developers/docs/core/accounts): Everything on Solana (balances, tokens, programs, app data) lives in accounts: records at an address, each with an owner that is allowed to change it.)</span></span> it owns.
- **The private key** proves ownership. Whoever holds it can sign for the
  address, so it never leaves the wallet app, key file, or key management
  system that stores it.

Solana uses the Ed25519 signature scheme. The Solana CLI stores a keypair as a
JSON file containing a 64-byte array: the 32-byte secret followed by the
32-byte public key.

Not every address has a private key.
<span className="sol-chip" data-concept="pda"><Tooltip headline="Program-derived addresses" tip="A PDA is an address derived from a program plus some seeds. It has no private key, so only that program can sign for it, which makes it handy for storing app state at predictable addresses." cta="Learn more" href="/developers/docs/core/pda">Program-derived addresses</Tooltip><span className="nojs-only"> ([Program-derived addresses](/developers/docs/core/pda): A PDA is an address derived from a program plus some seeds. It has no private key, so only that program can sign for it, which makes it handy for storing app state at predictable addresses.)</span></span>
are derived from a program and some seeds, and only that program can sign for
them.

## Create a keypair

Creating a keypair is local and free: no network call. An account appears at
the address only once it's funded with SOL.

<Tabs>
<Tab title="Kit">
<div className="sol-tab-label">Kit</div>

```ts
import { generateKeyPairSigner } from "@solana/kit";

const signer = await generateKeyPairSigner();
console.log("address: ", signer.address);
```

<div className="sol-run" data-run="cookbook/wallets/create-keypair/create-core" data-tab="Kit" data-runner="generate-keypair">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Example output: each run generates a new key pair</span></div>
<div className="sol-run-out">

```text Output
address:  DxQ6RYwhfmX66AQCf3B8aL4P9EivuXnf8HQBkFZwZZFJ
```

</div>
<pre className="sol-run-live" aria-live="polite"></pre>
</div>

</Tab>
<Tab title="Web3.js v3">
<div className="sol-tab-label">Web3.js v3</div>

```ts
import { Keypair } from "@solana/web3.js";

const keypair = await Keypair.generate();
console.log("address:", keypair.publicKey.toBase58());
```

<div className="sol-run" data-run="cookbook/wallets/create-keypair/create-core" data-tab="Web3.js v3" data-runner="generate-keypair">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Example output: each run generates a new key pair</span></div>
<div className="sol-run-out">

```text Output
address: Ddws1nufDuX8c6Zjbb3piTmbHwv9mxsDknftuSVSsGdJ
```

</div>
<pre className="sol-run-live" aria-live="polite"></pre>
</div>

</Tab>
<Tab title="Rust">
<div className="sol-tab-label">Rust</div>

```rust
use solana_sdk::{signature::Keypair, signer::Signer};

fn main() {
    let keypair = Keypair::new();
    let address = keypair.pubkey();

    println!("address: {address}")
}
```

<div className="sol-run" data-run="cookbook/wallets/create-keypair/create-core" data-tab="Rust" data-runner="generate-keypair">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Example output: each run generates a new key pair</span></div>
<div className="sol-run-out">

```text Output
address: CLKDUYSkw17fnDwz4D56f2k2YjCwKBtTFPfcHfuGuER3
```

</div>
<pre className="sol-run-live" aria-live="polite"></pre>
</div>

</Tab>
<Tab title="Web3.js (legacy)">
<div className="sol-tab-label">Web3.js (legacy)</div>

<Warning>
  **`@solana/web3.js` 1.x is no longer actively maintained**

  It receives critical fixes only. Use [Kit](/developers/docs/clients/official/javascript#solana-kit) for new code. To migrate existing code, follow the [Kit upgrade guide](https://www.solanakit.com/docs/upgrade-guide), or the [web3.js v3 migration guide](https://github.com/solana-foundation/solana-web3.js/blob/main/docs/web3js-v1-to-v3-migration.md) to keep the class-based API.

  To run this code, install 1.x with `npm install @solana/web3.js@1`. A plain `npm install @solana/web3.js` installs v3, which this code doesn't run on.
</Warning>

```ts
import { Keypair } from "@solana/web3.js";

const keypair = Keypair.generate();
console.log("address:", keypair.publicKey.toBase58());
```

<div className="sol-run" data-run="cookbook/wallets/create-keypair/create-core" data-tab="Web3.js (legacy)" data-runner="generate-keypair">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Example output: each run generates a new key pair</span></div>
<div className="sol-run-out">

```text Output
address: 27FGjnR9yaNe6s53Z9YHigUMhQqhzUU14GXbgzwBHMqg
```

</div>
<pre className="sol-run-live" aria-live="polite"></pre>
</div>

</Tab>
</Tabs>

## Signatures

Every transaction is signed by the wallets it spends from. The first signature doubles as the transaction's ID, which is what your code gets back and looks up later.

A transaction lists the accounts that must approve it. The network checks every
signature before it runs any instruction, and rejects the transaction if one is
missing or invalid. The first signer is the **fee payer**, which doesn't have to
be your customer: with
<span className="sol-chip" data-concept="sponsorship"><Tooltip headline="Fee sponsorship" tip="By default, the transaction's fee payer needs a little SOL to pay its fee. A fee-payer service such as Kora lets your app pay instead, so customers only ever hold dollars." cta="Learn more" href="/developers/docs/core/fees/fee-sponsorship">fee sponsorship</Tooltip><span className="nojs-only"> ([Fee sponsorship](/developers/docs/core/fees/fee-sponsorship): By default, the transaction's fee payer needs a little SOL to pay its fee. A fee-payer service such as Kora lets your app pay instead, so customers only ever hold dollars.)</span>,</span> your
app signs as fee payer and covers the fee.

A signature is 64 bytes, usually shown as base58.

## Sign and verify a message

Wallets can also sign bytes that aren't a transaction, for example to prove a
user controls an address at sign-in. Anyone with the address can verify it.

<Tabs>
<Tab title="Kit">
<div className="sol-tab-label">Kit</div>

```ts
import {
  generateKeyPair,
  signBytes,
  verifySignature,
  getUtf8Encoder,
  getBase58Decoder,
} from "@solana/kit";

const keys = await generateKeyPair();
const message = getUtf8Encoder().encode("Hello, World!");
const signedBytes = await signBytes(keys.privateKey, message);

const decoded = getBase58Decoder().decode(signedBytes);
console.log("Signature:", decoded);

const verified = await verifySignature(keys.publicKey, signedBytes, message);
console.log("Verified:", verified);
```

<div className="sol-run" data-run="cookbook/wallets/sign-message/sign-core" data-tab="Kit">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Example output</span></div>
<div className="sol-run-out">

```text Output
Signature: 4u1mRhCwXhzRwiprmXQ6vZbR5PdHpq92YN274wbFBbe1oPbmbrC5uFYxhgHkvZnDaJoVexky99EYTy7jUZ9r6NMw
Verified: true
```

</div>
</div>

</Tab>
<Tab title="Web3.js v3">
<div className="sol-tab-label">Web3.js v3</div>

```ts
import { Keypair } from "@solana/web3.js";

const keypair = await Keypair.fromSecretKey(
  Uint8Array.from([
    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,
  ]),
);

const message = "The quick brown fox jumps over the lazy dog";
const messageBytes = new TextEncoder().encode(message);

const signature = await keypair.signBytes(messageBytes);
const result = await keypair.verifySignature(signature, messageBytes);

console.log("Verified:", result);
```

<div className="sol-run" data-run="cookbook/wallets/sign-message/sign-core" data-tab="Web3.js v3">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Example output</span></div>
<div className="sol-run-out">

```text Output
Verified: true
```

</div>
</div>

</Tab>
<Tab title="Rust">
<div className="sol-tab-label">Rust</div>

```rust
use anyhow::Result;
use solana_sdk::{signature::Keypair, signer::Signer};

fn main() -> Result<()> {
    let keypair_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,
    ];
    let keypair = Keypair::try_from(&keypair_bytes[..])?;
    let message = "The quick brown fox jumps over the lazy dog";

    let signature = keypair.sign_message(message.as_bytes());
    let is_valid_signature = signature.verify(&keypair.pubkey().to_bytes(), message.as_bytes());
    println!("Verified: {:?}", is_valid_signature);

    Ok(())
}
```

<div className="sol-run" data-run="cookbook/wallets/sign-message/sign-core" data-tab="Rust">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Example output</span></div>
<div className="sol-run-out">

```text Output
Verified: true
```

</div>
</div>

</Tab>
<Tab title="Web3.js (legacy)">
<div className="sol-tab-label">Web3.js (legacy)</div>

<Warning>
  **`@solana/web3.js` 1.x is no longer actively maintained**

  It receives critical fixes only. Use [Kit](/developers/docs/clients/official/javascript#solana-kit) for new code. To migrate existing code, follow the [Kit upgrade guide](https://www.solanakit.com/docs/upgrade-guide), or the [web3.js v3 migration guide](https://github.com/solana-foundation/solana-web3.js/blob/main/docs/web3js-v1-to-v3-migration.md) to keep the class-based API.

  To run this code, install 1.x with `npm install @solana/web3.js@1`. A plain `npm install @solana/web3.js` installs v3, which this code doesn't run on.
</Warning>

```ts
// In Solana Web3.js v1, we can use the TweetNaCl crypto library:
import { Keypair } from "@solana/web3.js";
import nacl from "tweetnacl";
import naclUtil from "tweetnacl-util";

const keypair = Keypair.fromSecretKey(
  Uint8Array.from([
    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,
  ]),
);

const message = "The quick brown fox jumps over the lazy dog";
const messageBytes = naclUtil.decodeUTF8(message);

const signature = nacl.sign.detached(messageBytes, keypair.secretKey);
const result = nacl.sign.detached.verify(
  messageBytes,
  signature,
  keypair.publicKey.toBytes(),
);

console.log("Verified:", result);
```

<div className="sol-run" data-run="cookbook/wallets/sign-message/sign-core" data-tab="Web3.js (legacy)">
<div className="sol-run-bar"><button type="button" className="sol-run-btn">Run</button><span className="sol-run-note">Example output</span></div>
<div className="sol-run-out">

```text Output
Verified: true
```

</div>
</div>

</Tab>
</Tabs>

## Wallets in apps and on servers

- **In the browser**, users keep their keys in a wallet app. Your app asks the
  wallet to sign and never sees the private key. See
  [React & Next.js](/developers/docs/frontend).
- **On a server**, your code signs with its own keypair, for example to pay fees
  for users or to send payouts. Load it from a secret store, or sign through a
  KMS or HSM with [Keychain](/developers/docs/tools/keychain). See
  [signing in production](/developers/docs/core/transactions/signing-in-production).
- **Never** put a private key in browser code, in a repository, or in logs.

## Recipes

- [Restore a keypair](/developers/cookbook/wallets/restore-keypair)
- [Verify a keypair](/developers/cookbook/wallets/verify-keypair)
- [Validate a public key](/developers/cookbook/wallets/check-publickey)
- [Generate a mnemonic](/developers/cookbook/wallets/generate-mnemonic)
- [Connect a wallet in React](/developers/cookbook/wallets/connect-wallet-react)
