Skip to Content
ModelsKeypair

Keypair

Keypair owns an Ed25519 signing key and its corresponding PublicKey.

from solathon import Keypair keypair = Keypair() signature = keypair.sign(b"message").signature

The constructor generates a new keypair when called without an argument. It also accepts a 32-byte seed, a PyNaCl SigningKey or PrivateKey, or a solders.keypair.Keypair.

Import existing key material

from_private_key accepts a base58 string or a 32-byte seed / canonical 64-byte Solana keypair, supplied as bytes, a bytearray, or a list of integers.

import os from solathon import Keypair from_base58 = Keypair.from_private_key(os.environ["SOLANA_PRIVATE_KEY"]) from_solana_cli = Keypair.from_file("~/.config/solana/id.json") deterministic = Keypair.from_seed(bytes(range(32)))

Treat private_key, bytes(keypair), and Solana CLI keypair files as secrets. Never log or commit them.

Interoperate with solders

native_keypair = keypair.to_solders() same_keypair = Keypair.from_solders(native_keypair)

Attributes

  • public_key is the immutable 32-byte PublicKey.
  • private_key is an immutable 64-byte PrivateKey containing the seed and matching public key.
  • key_pair is the underlying PyNaCl SigningKey.

str(private_key) and repr(private_key) are redacted. Use bytes(keypair), bytes(private_key), or private_key.base58_encode() only at an explicit secret export boundary.