Client

The base client object used to interact with the blockchain. This is where it all begins.

class Client(endpoint: str, local: bool=False)
copy

To initialize a client, one of the three RPC cluster endpoint URLs must be passed. When running a local cluster, the local argument must be passed as true for the local endpoint to work.

Methods

Attributes

Methods

.refresh_http

Refreshes the HTTP client interacting with the JSON RPC.

def refresh_http()
copy

.get_account_info

Returns the account's information through the provided public key argument.

def get_account_info(public_key: PublicKey | str)
copy

.get_balance

Returns the account's balance in lamports through the provided public key argument.

def get_balance(public_key: PublicKey | str)
copy

.get_block

Returns identity and transaction information about a confirmed block in the ledger by the slot provided.

def get_block(slot: int)
copy

.get_block_height

Returns the current block height of the node.

def get_block_height()
copy

.get_block_production

Returns recent block production information from the current or previous epoch.

def get_block_production()
copy

.get_block_commitment

Returns commitment for particular block identified by slot.

def get_block_commitment(block: int)
copy

.get_blocks

Returns a list of confirmed blocks between two slots, end_slot is optional

def get_blocks(start_slot: int, end_slot: int | None = None)
copy

.get_blocks_with_limit

Returns a list of confirmed blocks starting from a given slot to a limit.

def get_blocks_with_limit(start_slot: int, limit)
copy

.get_block_time

Returns the estimated production time of a block as Unix timestamp.

def get_block_time(block: int)
copy

.get_cluster_nodes

Returns information about all the nodes participating in the cluster.

def get_cluster_nodes()
copy

.get_epoch_info

Returns information about the current epoch

def get_epoch_info()
copy

.get_epoch_schedule

Returns epoch schedule information from this cluster's genesis config.

def get_epoch_schedule()
copy

.get_fee_for_message

Retuns the fee which network will charge for a particular message.

def get_fee_for_message(message: str)
copy
⚠️

This method is only available in solana-core v1.9 or newer

.get_fees

Returns a recent block hash from the ledger, a fee schedule that can be used to compute the cost of submitting a transaction using it, and the last slot in which the blockhash will be valid.

def get_fees()
copy

.get_first_available_block

Returns the slot of the lowest confirmed block that has not been purged from the ledger.

def get_first_available_block()
copy

.get_genesis_hash

Returns the genesis hash.

def get_genesis_hash()
copy

.get_health

Returns the current health of the node.

def get_health()
copy

.get_identity

Returns the identity public key for the current node.

def get_identity()
copy

.get_inflation_governor

Returns the current inflation governor.

def get_inflation_governor()
copy

.get_inflation_rate

Returns the inflation / staking reward for a list of addresses for an epoch

def get_inflation_rate()
copy

.get_inflation_reward

Returns the specific inflation values for the current epoch.

def get_inflation_reward()
copy

.get_largest_accounts

Returns the 20 largest accounts, by lamport balance (results may be cached up to two hours). Currently if using get_largest_accounts you will need to nest the method inside of a try/except block and make an exception for a TimeoutError.

def get_largest_accounts()
copy

.get_leader_schedule

Returns the leader schedule for an epoch. Lots of data!

def get_leader_schedule()
copy

.get_max_retransmit_slot

Get the max slot seen from retransmit stage.

def get_max_retransmit_slot()
copy

.get_max_shred_insert_slot

Get the max slot seen from after shred insert.

def get_max_shred_insert_slot()
copy

.get_minimum_balance_for_rent_exemption

Returns minimum balance required to make account rent exempt.

def get_minimum_balance_for_rent_exmeption()
copy

.get_multiple_accounts

Returns the account information for a list of Pubkeys.

def get_multiple_accounts()
copy

.get_program_accounts

Returns all accounts owned by the provided program Pubkey.

def get_program_accounts()
copy

.get_recent_blockhash

Returns a recent block hash from the ledger, and a fee schedule that can be used to compute the cost of submitting a transaction using it.

def get_recent_blockhash()
copy

.get_recent_performance_samples

Returns a list of recent performance samples, in reverse slot order. Performance samples are taken every 60 seconds and include the number of transactions and slots that occur in a given time window.

def get_recent_performance_samples()
copy

.get_signatures_for_address

Returns signatures for confirmed transactions that include the given address in their accountKeys list. Returns signatures backwards in time from the provided signature or most recent confirmed block

def get_signatures_for_address()
copy

.get_signature_statuses

Returns the statuses of a list of signatures. Unless the searchTransactionHistory configuration parameter is included, this method only searches the recent status cache of signatures, which retains statuses for all active slots plus MAX_RECENT_BLOCKHASHES rooted slots.

def get_signature_statuses()
copy

.get_slot

Returns the slot that has reached the given or default commitment level

def get_slot()
copy

.get_supply

Returns information about the current supply.

def get_supply()
copy

.get_token_accounts_by_owner

Returns all SPL Token accounts of the public key provided. Either mint_id or program_id keyword argument is required, encoding is optional.

def get_token_accounts_by_owner(public_key: PublicKey | str, **kwargs)
copy

Example:

from solathon import Client, PublicKey
client = Client("https://api.mainnet-beta.solana.com")
public_key = PublicKey("B3BhJ1nvPvEhx3hq3nfK8hx4WYcKZdbhavSobZEA44ai")
program_id = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" # Token program ID
tokens = client.get_token_accounts_by_owner(public_key, program_id=program_id)
print(tokens)
copy

.get_token_account_balance

Returns balance of tokens held in the specified token account

def get_token_account_balance(public_key: PublicKey | str, **kwargs)
copy

Example:

from solathon import Client, PublicKey
client = Client("https://api.mainnet-beta.solana.com")
token_account = "FhmH5YDUX9gPKUFtNR95sFKsdprz49Ffv1VXjxzPWQti" # Token account public key
tokens = client.get_token_account_balance(token_account)
print(tokens)
copy

.get_transaction

Sends a request to the Solana RPC endpoint to retrieve a transaction by its signature.

def get_transaction(self, signature: Text, commitment: Optional[Commitment]=None) -> RPCResponse[TransactionElementType] | TransactionElement
copy

.request_airdrop

Requests the amount of lamport specified to be airdropped to the public key.

def request_airdrop(public_key: PublicKey, lamports: int)
copy

.send_transaction

Submits a signed Transaction object to the cluster for processing.

def send_transaction(transaction: Transaction)
copy

Example:

import time
from solathon.core.instructions import transfer
from solathon import Client, Transaction, PublicKey, Keypair
client = Client("https://api.devnet.solana.com")
sender = Keypair()
receiver = PublicKey("B3BhJ1nvPvEhx3hq3nfK8hx4WYcKZdbhavSobZEA44a")
amount = 10000 # This is the amount in lamports
# Requesting airdrop to get some devnet tokens for the transaction to succeed
res = client.request_airdrop(sender.public_key, amount + amount)
print("Airdrop response: ", res)
# 20 second delay to make sure we get enough time to receive airdrop tokens
time.sleep(20)
# Creating transfer instruction
instruction = transfer(
from_public_key=sender.public_key,
to_public_key=receiver,
lamports=100
)
transaction = Transaction(instructions=[instruction], signers=[sender])
result = client.send_transaction(transaction)
print("Transaction response:", result)
copy

Attributes

.endpoint

Returns the endpoint which the client is currently using.

.http

Returns the http object being used to interact with the JSON RPC.