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

# How to Validate a Public Key

> Public keys on Solana can be validated with a small amount of code. Learn how to validate public keys on Solana.

In certain special cases (e.g. a program-derived address), public keys may not
have a private key associated with them. You can check this by looking to see if
the public key lies on the ed25519 curve. Only public keys that lie on the curve
can be controlled by users with wallets.

The Kit tab asks the opposite question: `isOffCurveAddress` returns `true` for
an address that is off the curve, such as a program-derived address.

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

```ts
import { address, isOffCurveAddress } from "@solana/kit";

// on curve address
const key = address("5oNDL3swdJJF1g9DzJiZ4ynHXgszjAEpUkxVYejchzrY");
console.log("is off curve:", isOffCurveAddress(key));

const offCurveAddress = address("4BJXYkfvg37zEmBbsacZjeQDpTNx91KppxFJxRqrz48e");
console.log("is off curve:", isOffCurveAddress(offCurveAddress));
```

<div className="sol-run" data-run="cookbook/wallets/check-publickey/check" 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
is off curve: false
is off curve: true
```

</div>
</div>

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

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

// on curve address
const key = new PublicKey("5oNDL3swdJJF1g9DzJiZ4ynHXgszjAEpUkxVYejchzrY");
console.log(PublicKey.isOnCurve(key.toBytes()));

const offCurveAddress = new PublicKey(
  "4BJXYkfvg37zEmBbsacZjeQDpTNx91KppxFJxRqrz48e",
);
console.log(PublicKey.isOnCurve(offCurveAddress.toBytes()));
```

<div className="sol-run" data-run="cookbook/wallets/check-publickey/check" 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
true
false
```

</div>
</div>

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

```rust
use anyhow::Result;
use solana_sdk::pubkey;

fn main() -> Result<()> {
    // on curve address
    let on_curve_public_key = pubkey!("5oNDL3swdJJF1g9DzJiZ4ynHXgszjAEpUkxVYejchzrY");
    println!("is on curve: {}", on_curve_public_key.is_on_curve());

    let off_curve_public_key = pubkey!("4BJXYkfvg37zEmBbsacZjeQDpTNx91KppxFJxRqrz48e");
    println!("is on curve: {}", off_curve_public_key.is_on_curve());
    Ok(())
}
```

<div className="sol-run" data-run="cookbook/wallets/check-publickey/check" 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
is on curve: true
is on curve: false
```

</div>
</div>

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

```py
from solders.pubkey import Pubkey

# on curve address
key = Pubkey.from_string("5oNDL3swdJJF1g9DzJiZ4ynHXgszjAEpUkxVYejchzrY")
print(key.is_on_curve())

off_curve_address = Pubkey.from_string("4BJXYkfvg37zEmBbsacZjeQDpTNx91KppxFJxRqrz48e")
print(off_curve_address.is_on_curve())
```

<div className="sol-run" data-run="cookbook/wallets/check-publickey/check" data-tab="Python">
<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
True
False
```

</div>
</div>

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

```go
package main

import (
	"fmt"

	"github.com/solana-foundation/solana-go/v2"
)

func main() {
	// on curve address
	key := solana.MustPublicKeyFromBase58("5oNDL3swdJJF1g9DzJiZ4ynHXgszjAEpUkxVYejchzrY")
	fmt.Println(key.IsOnCurve())

	offCurveAddress := solana.MustPublicKeyFromBase58("4BJXYkfvg37zEmBbsacZjeQDpTNx91KppxFJxRqrz48e")
	fmt.Println(offCurveAddress.IsOnCurve())
}
```

<div className="sol-run" data-run="cookbook/wallets/check-publickey/check" data-tab="Go">
<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
true
false
```

</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
import { PublicKey } from "@solana/web3.js";

// on curve address
const key = new PublicKey("5oNDL3swdJJF1g9DzJiZ4ynHXgszjAEpUkxVYejchzrY");
console.log(PublicKey.isOnCurve(key.toBytes()));

const offCurveAddress = new PublicKey(
  "4BJXYkfvg37zEmBbsacZjeQDpTNx91KppxFJxRqrz48e",
);
console.log(PublicKey.isOnCurve(offCurveAddress.toBytes()));
```

<div className="sol-run" data-run="cookbook/wallets/check-publickey/check" 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
true
false
```

</div>
</div>

</Tab>
</Tabs>
