isOffCurveAddress returns true for
an address that is off the curve, such as a program-derived address.
- Kit
- Web3.js v3
- Rust
- Python
- Go
- Web3.js (legacy)
Kit
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));
Example output
Output
is off curve: false
is off curve: true
Web3.js v3
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()));
Example output
Output
true
false
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(())
}
Example output
Output
is on curve: true
is on curve: false
Python
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())
Example output
Output
True
False
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())
}
Example output
Output
true
false
Web3.js (legacy)
@solana/web3.js 1.x is no longer actively maintainedIt receives critical fixes only. Use Kit for new code. To migrate existing code, follow the Kit upgrade guide, or the web3.js v3 migration guide 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.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()));
Example output
Output
true
false