Client
The base client object used to interact with the blockchain. This is where it all begins.
class Client(endpoint: str, local: bool=False)
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
- refresh_http
- get_account_info
- get_balance
- get_block
- get_block_height
- get_block_production
- get_block_commitment
- get_blocks
- get_blocks_with_limit
- get_block_time
- get_cluster_nodes
- get_epoch_info
- get_epoch_schedule
- get_fee_for_message
- get_first_available_block
- get_genesis_hash
- get_health
- get_identity
- get_inflation_governor
- get_inflation_rate
- get_inflation_reward
- get_largest_accounts
- get_leader_schedule
- get_max_retransmit_slot
- get_max_shred_insert_slot
- get_minimum_balance_for_rent_exmeption
- get_multiple_accounts
- get_program_accounts
- get_latest_blockhash
- get_recent_performance_samples
- get_signatures_for_address
- get_signature_statuses
- get_supply
- get_token_accounts_by_owner
- get_token_account_balance
- get_transaction
- request_airdrop
- send_transaction
Attributes
Methods
.refresh_http
Refreshes the HTTP client interacting with the JSON RPC.
def refresh_http()
.get_account_info
Returns the account's information through the provided public key argument.
def get_account_info(public_key: PublicKey | str)
.get_balance
Returns the account's balance in lamports through the provided public key argument.
def get_balance(public_key: PublicKey | str)
.get_block
Returns identity and transaction information about a confirmed block in the ledger by the slot provided.
def get_block(slot: int)
.get_block_height
Returns the current block height of the node.
def get_block_height()
.get_block_production
Returns recent block production information from the current or previous epoch.
def get_block_production()
.get_block_commitment
Returns commitment for particular block identified by slot.
def get_block_commitment(block: int)
.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)
.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)
.get_block_time
Returns the estimated production time of a block as Unix timestamp.
def get_block_time(block: int)
.get_cluster_nodes
Returns information about all the nodes participating in the cluster.
def get_cluster_nodes()
.get_epoch_info
Returns information about the current epoch
def get_epoch_info()
.get_epoch_schedule
Returns epoch schedule information from this cluster's genesis config.
def get_epoch_schedule()
.get_fee_for_message
Retuns the fee which network will charge for a particular message.
def get_fee_for_message(message: str)
.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()
.get_genesis_hash
Returns the genesis hash.
def get_genesis_hash()
.get_health
Returns the current health of the node.
def get_health()
.get_identity
Returns the identity public key for the current node.
def get_identity()
.get_inflation_governor
Returns the current inflation governor.
def get_inflation_governor()
.get_inflation_rate
Returns the inflation / staking reward for a list of addresses for an epoch
def get_inflation_rate()
.get_inflation_reward
Returns the specific inflation values for the current epoch.
def get_inflation_reward()
.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()
.get_leader_schedule
Returns the leader schedule for an epoch. Lots of data!
def get_leader_schedule()
.get_max_retransmit_slot
Get the max slot seen from retransmit stage.
def get_max_retransmit_slot()
.get_max_shred_insert_slot
Get the max slot seen from after shred insert.
def get_max_shred_insert_slot()
.get_minimum_balance_for_rent_exemption
Returns minimum balance required to make account rent exempt.
def get_minimum_balance_for_rent_exmeption()
.get_multiple_accounts
Returns the account information for a list of Pubkeys.
def get_multiple_accounts()
.get_program_accounts
Returns all accounts owned by the provided program Pubkey.
def get_program_accounts()
.get_latest_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_latest_blockhash()
.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()
.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(address: str, limit: Optional[str], until: Optional[str], before: Optional[str])
.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()
.get_slot
Returns the slot that has reached the given or default commitment level
def get_slot()
.get_supply
Returns information about the current supply.
def get_supply()
.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)
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)
.get_token_account_balance
Returns balance of tokens held in the specified token account
def get_token_account_balance(public_key: PublicKey | str, **kwargs)
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)
.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
.request_airdrop
Requests the amount of lamport specified to be airdropped to the public key.
def request_airdrop(public_key: PublicKey, lamports: int)
.send_transaction
Submits a signed Transaction object to the cluster for processing.
def send_transaction(transaction: Transaction)
Example:
import timefrom solathon.core.instructions import transferfrom 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 succeedres = 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 tokenstime.sleep(20)
# Creating transfer instructioninstruction = 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)
Attributes
.endpoint
Returns the endpoint which the client is currently using.
.http
Returns the http object being used to interact with the JSON RPC.