AsyncClient

The base async client object used to interact with the blockchain. This is identical to normal sync client, the only difference is that all methods are asynchronous.

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

To initialize an async 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.

async def refresh_http()
copy

.get_account_info

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

async def get_account_info(public_key: PublicKey | str)
copy

.get_balance

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

async 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.

async def get_block(slot: int)
copy

.get_block_height

Returns the current block height of the node.

async def get_block_height()
copy

.get_block_production

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

async def get_block_production()
copy

.get_block_commitment

Returns commitment for particular block identified by slot.

async def get_block_commitment(block: int)
copy

.get_blocks

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

async 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.

async def get_blocks_with_limit(start_slot: int, limit)
copy

.get_block_time

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

async def get_block_time(block: int)
copy

.get_cluster_nodes

Returns information about all the nodes participating in the cluster.

async def get_cluster_nodes()
copy

.get_epoch_info

Returns information about the current epoch

async def get_epoch_info()
copy

.get_epoch_schedule

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

async def get_epoch_schedule()
copy

.get_fee_for_message

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

async def get_fee_for_message(message: str)
copy
⚠️

This method is only available in solana-core v1.9 or newer. For now, use get_fees method.

.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.

async def get_fees()
copy

.get_first_available_block

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

async def get_first_available_block()
copy

.get_genesis_hash

Returns the genesis hash.

async def get_genesis_hash()
copy

.get_health

Returns the current health of the node.

async def get_health()
copy

.get_identity

Returns the identity public key for the current node.

async def get_identity()
copy

.get_inflation_governor

Returns the current inflation governor.

async def get_inflation_governor()
copy

.get_inflation_rate

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

async def get_inflation_rate()
copy

.get_inflation_reward

Returns the specific inflation values for the current epoch.

async 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.

async def get_largest_accounts()
copy

.get_leader_schedule

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

async def get_leader_schedule()
copy

.get_max_retransmit_slot

Get the max slot seen from retransmit stage.

async def get_max_retransmit_slot()
copy

.get_max_shred_insert_slot

Get the max slot seen from after shred insert.

async def get_max_shred_insert_slot()
copy

.get_minimum_balance_for_rent_exemption

Returns minimum balance required to make account rent exempt.

async def get_minimum_balance_for_rent_exmeption()
copy

.get_multiple_accounts

Returns the account information for a list of Pubkeys.

async def get_multiple_accounts()
copy

.get_program_accounts

Returns all accounts owned by the provided program Pubkey.

async 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.

async 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.

async 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

async def get_signatures_for_address()
copy

.get_supply

Returns information about the current supply.

async 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.

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

Example:

import asyncio
from solathon import AsyncClient, PublicKey
def main():
client = AsyncClient("https://api.mainnet-beta.solana.com")
public_key = PublicKey("B3BhJ1nvPvEhx3hq3nfK8hx4WYcKZdbhavSobZEA44ai")
program_id = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" # Token program ID
tokens = await client.get_token_accounts_by_owner(public_key, program_id=program_id)
print(tokens)
asyncio.run(main())
copy
⚠️

This method returns token on mainnet only.

.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.

async 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.

async def request_airdrop(public_key: PublicKey | lamports: int)
copy

.send_transaction

Submits a signed Transaction object to the cluster for processing.

async def send_transaction(transaction: Transaction)
copy

Example:

import time
import asyncio
from solathon.core.instructions import transfer
from solathon import AsyncClient, Transaction, PublicKey, Keypair
def main():
client = AsyncClient("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 = await 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 = await client.send_transaction(transaction)
print("Transaction response: ", result)
asyncio.run(main())
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.