Solders

0.27.1 · active · verified Sun Apr 12

Solders is a high-performance Python toolkit for Solana, providing robust solutions for core SDK functionalities like keypairs, pubkeys, transaction signing and serialization, and RPC request/response parsing. It serves as a Python binding to the Solana Rust SDK, aiming to avoid reimplementing Solana logic in pure Python. While `solana-py` handles network interaction and SPL token clients, `solders` focuses on low-level primitives and offers a `litesvm` module for faster integration testing. The library is actively maintained with frequent updates, with the current version being 0.27.1.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a basic Solana transaction using `solders` primitives. It generates a keypair, defines an instruction, constructs a message, and finally builds a transaction. Note that `solders` focuses on data structures and cryptography; network interaction (like sending the transaction) is typically handled by `solana-py`.

from solders.message import Message
from solders.keypair import Keypair
from solders.instruction import Instruction
from solders.hash import Hash
from solders.transaction import Transaction
from solders.pubkey import Pubkey

# Generate a new keypair for the payer (replace with a real keypair in production)
payer = Keypair()

# Define a program ID and some arbitrary instruction data
program_id = Pubkey.new_unique() # Using new_unique for a placeholder program ID
arbitrary_instruction_data = bytes([1, 2, 3])
accounts = [] # For a simple instruction, no accounts might be needed

# Create an instruction
instruction = Instruction(program_id, arbitrary_instruction_data, accounts)

# Create a message from the instruction and payer's public key
message = Message([instruction], payer.pubkey())

# Replace with a real blockhash from an RPC call in a real application
# For demonstration, we use a default hash.
blockhash = Hash.default() 

# Create a transaction
tx = Transaction([payer], message, blockhash)

# In a real application, you would sign and send the transaction:
# from solana.rpc.api import Client
# rpc_client = Client("https://api.devnet.solana.com") # Example RPC URL
# # For this example, we won't actually send the transaction.
# # signature = rpc_client.send_transaction(tx).value
# # print(f"Transaction sent: {signature}")

print("Transaction created successfully (not sent in this example).")
print(f"Payer Public Key: {payer.pubkey()}")
print(f"Transaction Message: {message}")
print(f"Transaction: {tx}")

view raw JSON →