or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

account-management.mdcryptographic-primitives.mderror-handling.mdindex.mdnetwork-sysvars.mdrpc-functionality.mdsystem-programs.mdtesting-infrastructure.mdtoken-operations.mdtransaction-construction.mdtransaction-status.md
tile.json

tessl/pypi-solders

Python bindings for Solana Rust tools providing high-performance blockchain development primitives, RPC functionality, and testing infrastructure.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/solders@0.26.x

To install, run

npx @tessl/cli install tessl/pypi-solders@0.26.0

index.mddocs/

Solders

A high-performance Python library for interacting with the Solana blockchain. Solders provides Python bindings to core Solana Rust libraries, offering fast serialization/deserialization, cryptographic operations, transaction building, and RPC client functionality with native-level performance.

Package Information

  • Package Name: solders
  • Language: Python
  • Installation: pip install solders
  • Version: 0.26.0

Core Imports

import solders

Essential core types for blockchain operations:

from solders.pubkey import Pubkey
from solders.keypair import Keypair
from solders.signature import Signature
from solders.hash import Hash

Transaction building imports:

from solders.transaction import Transaction, VersionedTransaction
from solders.instruction import Instruction, AccountMeta
from solders.message import Message, MessageV0

System operations:

from solders.system_program import transfer, TransferParams
from solders.compute_budget import set_compute_unit_limit

Basic Usage

Creating a Simple Transfer Transaction

from solders.keypair import Keypair
from solders.pubkey import Pubkey
from solders.transaction import Transaction
from solders.system_program import transfer, TransferParams
from solders.hash import Hash

# Generate keypairs
sender = Keypair()
recipient = Keypair()

# Create transfer instruction
transfer_ix = transfer(TransferParams(
    from_pubkey=sender.pubkey(),
    to_pubkey=recipient.pubkey(),
    lamports=1000000  # 0.001 SOL
))

# Create transaction
recent_blockhash = Hash.from_string("11111111111111111111111111111112")  # Example
tx = Transaction.new_with_payer([transfer_ix], sender.pubkey())
tx.recent_blockhash = recent_blockhash

# Sign transaction
tx.sign([sender], recent_blockhash)

Working with Public Keys

from solders.pubkey import Pubkey

# Create from string
pubkey = Pubkey.from_string("11111111111111111111111111111112")

# Create from bytes
pubkey_bytes = bytes(32)  # 32 zero bytes
pubkey = Pubkey(pubkey_bytes)

# Get program derived address
seeds = [b"metadata", bytes(pubkey)]
program_id = Pubkey.from_string("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")
pda, bump = Pubkey.find_program_address(seeds, program_id)

Creating Instructions

from solders.instruction import Instruction, AccountMeta
from solders.pubkey import Pubkey

# Create account metadata
accounts = [
    AccountMeta(pubkey=sender.pubkey(), is_signer=True, is_writable=True),
    AccountMeta(pubkey=recipient.pubkey(), is_signer=False, is_writable=True)
]

# Create instruction
instruction = Instruction(
    program_id=Pubkey.from_string("11111111111111111111111111111112"),
    accounts=accounts,
    data=bytes([0, 1, 2, 3])  # Instruction data
)

Architecture

Solders is organized into functional modules that mirror Solana's core architecture:

  • Cryptographic Layer: Ed25519 keypairs, signatures, and SHA-256 hashing primitives
  • Transaction Layer: Message construction, instruction building, and transaction formatting
  • Program Layer: System program, compute budget, and token program interactions
  • Network Layer: RPC client operations, commitment levels, and network configuration
  • State Layer: Account management, sysvars, and blockchain state representations

The library leverages Rust's performance through native extensions while providing Pythonic interfaces. Most functionality is exposed through a native extension module solders.solders, ensuring fast serialization and cryptographic operations essential for blockchain interactions.

Optional Dependencies

  • RPC functionality requires the ring cryptographic library
  • LiteSVM testing requires additional native dependencies

Capabilities

Cryptographic Primitives

Core blockchain cryptography including Ed25519 keypairs, signatures, public keys, and SHA-256 hashing. These primitives form the foundation for all Solana operations.

class Pubkey:
    def __init__(self, value: bytes): ...
    @classmethod
    def from_string(cls, s: str) -> 'Pubkey': ...
    @staticmethod
    def find_program_address(seeds: List[bytes], program_id: 'Pubkey') -> Tuple['Pubkey', int]: ...

class Keypair:
    def __init__(self): ...
    @classmethod
    def from_seed(cls, seed: bytes) -> 'Keypair': ...
    def pubkey(self) -> Pubkey: ...
    def sign_message(self, message: bytes) -> 'Signature': ...

class Signature:
    def __init__(self, signature_bytes: bytes): ...
    @classmethod
    def from_string(cls, s: str) -> 'Signature': ...

class Hash:
    def __init__(self, value: bytes): ...
    @classmethod
    def from_string(cls, s: str) -> 'Hash': ...

Cryptographic Primitives

Transaction Construction

Transaction and message building with support for both legacy and versioned formats, including address lookup tables and instruction compilation.

class Transaction:
    def __init__(self, instructions: List[Instruction], payer: Optional[Pubkey]): ...
    @staticmethod
    def new_with_payer(instructions: List[Instruction], payer: Optional[Pubkey]) -> 'Transaction': ...
    def sign(self, signers: List[Union[Keypair, Presigner]], recent_blockhash: Hash) -> None: ...

class VersionedTransaction:
    def __init__(self, message: VersionedMessage, signatures: List[Signature]): ...

class Instruction:
    def __init__(self, program_id: Pubkey, accounts: List[AccountMeta], data: bytes): ...

class AccountMeta:
    def __init__(self, pubkey: Pubkey, is_signer: bool, is_writable: bool): ...

Transaction Construction

Account Management

Account data structures, encoding formats, and metadata handling for both raw and parsed account information.

class Account:
    def __init__(self, lamports: int, data: bytes, owner: Pubkey, executable: bool, rent_epoch: int): ...

class UiAccountEncoding:
    Base64: 'UiAccountEncoding'
    JsonParsed: 'UiAccountEncoding'
    Base58: 'UiAccountEncoding'

class CommitmentConfig:
    def __init__(self, commitment: CommitmentLevel): ...

class CommitmentLevel:
    Processed: 'CommitmentLevel'
    Confirmed: 'CommitmentLevel'
    Finalized: 'CommitmentLevel'

Account Management

System Programs

Built-in Solana programs including the System program for account creation and transfers, and the Compute Budget program for transaction optimization.

def transfer(params: TransferParams) -> Instruction: ...
def create_account(params: CreateAccountParams) -> Instruction: ...
def allocate(params: AllocateParams) -> Instruction: ...

def set_compute_unit_limit(units: int) -> Instruction: ...
def set_compute_unit_price(micro_lamports: int) -> Instruction: ...
def request_heap_frame(bytes: int) -> Instruction: ...

# Address lookup table operations
def create_lookup_table(params: CreateLookupTableParams) -> Instruction: ...
def extend_lookup_table(params: ExtendLookupTableParams) -> Instruction: ...
def close_lookup_table(params: CloseLookupTableParams) -> Instruction: ...

System Programs

Token Operations

SPL Token program support including token account management, associated token addresses, and token state parsing.

def get_associated_token_address(owner: Pubkey, mint: Pubkey) -> Pubkey: ...

class Mint:
    def __init__(self, mint_authority: Optional[Pubkey], supply: int, decimals: int, ...): ...

class TokenAccount:
    def __init__(self, mint: Pubkey, owner: Pubkey, amount: int, ...): ...

class TokenAccountState:
    Uninitialized: 'TokenAccountState'
    Initialized: 'TokenAccountState'
    Frozen: 'TokenAccountState'

Token Operations

RPC Functionality

Comprehensive RPC client support with request/response handling, configuration options, and subscription capabilities for interacting with Solana networks.

class GetAccountInfo:
    def __init__(self, pubkey: Pubkey, config: Optional[RpcAccountInfoConfig]): ...

class GetBalance:
    def __init__(self, pubkey: Pubkey, config: Optional[CommitmentConfig]): ...

class GetTransaction:
    def __init__(self, signature: Signature, config: Optional[RpcTransactionConfig]): ...

class RpcAccountInfoConfig:
    def __init__(self, encoding: Optional[UiAccountEncoding], ...): ...

RPC Functionality

Network and Sysvars

Network configuration, system variables, and blockchain state including clock information, rent parameters, and epoch scheduling.

class Clock:
    def __init__(self, slot: int, epoch_start_timestamp: Optional[int], epoch: int, ...): ...

class Rent:
    def __init__(self, lamports_per_byte_year: int, exemption_threshold: float, burn_percent: int): ...

class EpochInfo:
    def __init__(self, epoch: int, slot_index: int, slots_in_epoch: int, ...): ...

class EpochSchedule:
    def __init__(self, slots_per_epoch: int, leader_schedule_slot_offset: int, ...): ...

Network and Sysvars

Transaction Status

Transaction metadata, execution results, and status tracking including error handling and parsed transaction data.

class TransactionStatus:
    def __init__(self, slot: int, confirmations: Optional[int], ...): ...

class UiTransactionStatusMeta:
    def __init__(self, err: Optional[TransactionErrorType], fee: int, ...): ...

class ParsedInstruction:
    def __init__(self, program: str, program_id: Pubkey, parsed: dict): ...

TransactionErrorType = Union[TransactionErrorFieldless, TransactionErrorInstructionError, ...]

Transaction Status

Testing Infrastructure

LiteSVM lightweight runtime for local testing and transaction simulation without requiring a full Solana network.

class LiteSVM:
    def __init__(self): ...
    def send_transaction(self, transaction: Union[Transaction, VersionedTransaction]) -> TransactionResult: ...
    def get_account(self, pubkey: Pubkey) -> Optional[Account]: ...
    def get_balance(self, pubkey: Pubkey) -> int: ...

TransactionResult = Union[TransactionMetadata, FailedTransactionMetadata]

Testing Infrastructure

Error Handling

Comprehensive error types for transaction processing, serialization, signing operations, and RPC communications.

class SignerError(Exception): ...
class BincodeError(Exception): ...
class SerdeJSONError(Exception): ...
class SanitizeError(Exception): ...
class TransactionError(Exception): ...
class ParseHashError(Exception): ...

Error Handling