or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

index.mdrpc-client.mdtoken-operations.mdutilities.md

rpc-client.mddocs/

0

# RPC Client Operations

1

2

Complete Solana JSON-RPC API client with synchronous and asynchronous interfaces. The RPC client provides comprehensive access to the Solana blockchain network, including account queries, transaction operations, network information, and real-time WebSocket subscriptions.

3

4

## Capabilities

5

6

### Client Initialization

7

8

Creates RPC clients for connecting to Solana clusters with configurable endpoints, commitment levels, timeouts, and connection parameters.

9

10

```python { .api }

11

class Client:

12

def __init__(self, endpoint: str, commitment: Optional[Commitment] = None, timeout: float = 30, extra_headers: Optional[Dict[str, str]] = None, proxy: Optional[str] = None):

13

"""

14

Initialize synchronous RPC client.

15

16

Parameters:

17

- endpoint: RPC endpoint URL (e.g., "https://api.mainnet-beta.solana.com")

18

- commitment: Default commitment level for requests

19

- timeout: Request timeout in seconds

20

- extra_headers: Additional HTTP headers

21

- proxy: Proxy URL if needed

22

"""

23

24

class AsyncClient:

25

def __init__(self, endpoint: str, commitment: Optional[Commitment] = None, timeout: float = 30, extra_headers: Optional[Dict[str, str]] = None, proxy: Optional[str] = None):

26

"""

27

Initialize asynchronous RPC client.

28

29

Parameters:

30

- endpoint: RPC endpoint URL (e.g., "https://api.mainnet-beta.solana.com")

31

- commitment: Default commitment level for requests

32

- timeout: Request timeout in seconds

33

- extra_headers: Additional HTTP headers

34

- proxy: Proxy URL if needed

35

"""

36

37

def is_connected(self) -> bool:

38

"""Check if client is connected to the RPC endpoint."""

39

```

40

41

### Account Operations

42

43

Retrieve account information, balances, and query multiple accounts efficiently with support for different data encodings and filtering options.

44

45

```python { .api }

46

def get_balance(self, pubkey: Pubkey, commitment: Optional[Commitment] = None) -> GetBalanceResp:

47

"""

48

Get SOL balance for an account.

49

50

Parameters:

51

- pubkey: Account public key

52

- commitment: Commitment level for the query

53

54

Returns:

55

GetBalanceResp with value field containing lamports

56

"""

57

58

def get_account_info(self, pubkey: Pubkey, commitment: Optional[Commitment] = None, encoding: str = "base64", data_slice: Optional[DataSliceOpts] = None) -> GetAccountInfoResp:

59

"""

60

Get account information and data.

61

62

Parameters:

63

- pubkey: Account public key

64

- commitment: Commitment level for the query

65

- encoding: Data encoding ("base64", "base58", "base64+zstd", "jsonParsed")

66

- data_slice: Optional data slice to retrieve partial account data

67

68

Returns:

69

GetAccountInfoResp with account details and data

70

"""

71

72

def get_account_info_json_parsed(self, pubkey: Pubkey, commitment: Optional[Commitment] = None) -> GetAccountInfoMaybeJsonParsedResp:

73

"""

74

Get account information with JSON-parsed data when possible.

75

76

Parameters:

77

- pubkey: Account public key

78

- commitment: Commitment level for the query

79

80

Returns:

81

GetAccountInfoMaybeJsonParsedResp with parsed account data

82

"""

83

84

def get_multiple_accounts(self, pubkeys: List[Pubkey], commitment: Optional[Commitment] = None, encoding: str = "base64", data_slice: Optional[DataSliceOpts] = None) -> GetMultipleAccountsResp:

85

"""

86

Get information for multiple accounts in a single request.

87

88

Parameters:

89

- pubkeys: List of account public keys (max 100)

90

- commitment: Commitment level for the query

91

- encoding: Data encoding for account data

92

- data_slice: Optional data slice for partial account data

93

94

Returns:

95

GetMultipleAccountsResp with array of account information

96

"""

97

98

def get_multiple_accounts_json_parsed(self, pubkeys: List[Pubkey], commitment: Optional[Commitment] = None) -> GetMultipleAccountsMaybeJsonParsedResp:

99

"""

100

Get multiple accounts with JSON-parsed data when possible.

101

102

Parameters:

103

- pubkeys: List of account public keys (max 100)

104

- commitment: Commitment level for the query

105

106

Returns:

107

GetMultipleAccountsMaybeJsonParsedResp with parsed account data

108

"""

109

```

110

111

### Transaction Operations

112

113

Send transactions, simulate execution, check transaction status, and confirm transaction completion with comprehensive transaction management capabilities.

114

115

```python { .api }

116

def send_transaction(self, txn: Transaction, opts: Optional[TxOpts] = None) -> SendTransactionResp:

117

"""

118

Send a signed transaction to the network.

119

120

Parameters:

121

- txn: Signed transaction object

122

- opts: Transaction options (skip_preflight, encoding, etc.)

123

124

Returns:

125

SendTransactionResp with transaction signature

126

"""

127

128

def send_raw_transaction(self, txn: bytes, opts: Optional[TxOpts] = None) -> SendTransactionResp:

129

"""

130

Send a raw transaction as bytes.

131

132

Parameters:

133

- txn: Serialized transaction bytes

134

- opts: Transaction options

135

136

Returns:

137

SendTransactionResp with transaction signature

138

"""

139

140

def simulate_transaction(self, txn: Transaction, sig_verify: bool = False, commitment: Optional[Commitment] = None) -> SimulateTransactionResp:

141

"""

142

Simulate transaction execution without sending to network.

143

144

Parameters:

145

- txn: Transaction to simulate

146

- sig_verify: Whether to verify signatures

147

- commitment: Commitment level for simulation

148

149

Returns:

150

SimulateTransactionResp with simulation results and logs

151

"""

152

153

def get_transaction(self, tx_sig: Signature, encoding: str = "json", commitment: Optional[Commitment] = None, max_supported_transaction_version: Optional[int] = None) -> GetTransactionResp:

154

"""

155

Get confirmed transaction details.

156

157

Parameters:

158

- tx_sig: Transaction signature

159

- encoding: Response encoding ("json", "jsonParsed", "base64", "base58")

160

- commitment: Commitment level

161

- max_supported_transaction_version: Max transaction version to support

162

163

Returns:

164

GetTransactionResp with transaction details

165

"""

166

167

def get_signature_statuses(self, signatures: List[Signature], search_transaction_history: bool = False) -> GetSignatureStatusesResp:

168

"""

169

Get status of transaction signatures.

170

171

Parameters:

172

- signatures: List of transaction signatures (max 256)

173

- search_transaction_history: Search transaction history if not found in recent cache

174

175

Returns:

176

GetSignatureStatusesResp with status for each signature

177

"""

178

179

def confirm_transaction(self, tx_sig: Signature, commitment: Optional[Commitment] = None, sleep_seconds: float = 0.5, last_valid_block_height: Optional[int] = None) -> GetSignatureStatusesResp:

180

"""

181

Wait for transaction confirmation.

182

183

Parameters:

184

- tx_sig: Transaction signature to confirm

185

- commitment: Commitment level to wait for

186

- sleep_seconds: Sleep duration between status checks

187

- last_valid_block_height: Block height after which to stop waiting

188

189

Returns:

190

GetSignatureStatusesResp when transaction is confirmed

191

"""

192

193

def get_signatures_for_address(self, account: Pubkey, before: Optional[Signature] = None, until: Optional[Signature] = None, limit: Optional[int] = None, commitment: Optional[Commitment] = None) -> GetSignaturesForAddressResp:

194

"""

195

Get transaction signatures for an address.

196

197

Parameters:

198

- account: Account public key

199

- before: Start searching backwards from this signature

200

- until: Search until this signature

201

- limit: Maximum number of signatures to return (max 1000)

202

- commitment: Commitment level

203

204

Returns:

205

GetSignaturesForAddressResp with array of signature information

206

"""

207

```

208

209

### Block Operations

210

211

Access block information, block heights, block time data, and blockchain progression with comprehensive block query capabilities.

212

213

```python { .api }

214

def get_block(self, slot: int, encoding: str = "json", max_supported_transaction_version: Optional[int] = None) -> GetBlockResp:

215

"""

216

Get block information for a specific slot.

217

218

Parameters:

219

- slot: Slot number

220

- encoding: Response encoding ("json", "jsonParsed", "base64", "base58")

221

- max_supported_transaction_version: Max transaction version to support

222

223

Returns:

224

GetBlockResp with block details and transactions

225

"""

226

227

def get_block_height(self, commitment: Optional[Commitment] = None) -> GetBlockHeightResp:

228

"""

229

Get current block height.

230

231

Parameters:

232

- commitment: Commitment level

233

234

Returns:

235

GetBlockHeightResp with current block height

236

"""

237

238

def get_block_time(self, slot: int) -> GetBlockTimeResp:

239

"""

240

Get estimated production time of a block.

241

242

Parameters:

243

- slot: Block slot number

244

245

Returns:

246

GetBlockTimeResp with Unix timestamp

247

"""

248

249

def get_blocks(self, start_slot: int, end_slot: Optional[int] = None) -> GetBlocksResp:

250

"""

251

Get list of confirmed blocks between two slots.

252

253

Parameters:

254

- start_slot: Start slot (inclusive)

255

- end_slot: End slot (inclusive), if None returns up to 500,000 blocks

256

257

Returns:

258

GetBlocksResp with array of block slot numbers

259

"""

260

261

def get_latest_blockhash(self, commitment: Optional[Commitment] = None) -> GetLatestBlockhashResp:

262

"""

263

Get latest blockhash.

264

265

Parameters:

266

- commitment: Commitment level

267

268

Returns:

269

GetLatestBlockhashResp with blockhash and last valid block height

270

"""

271

272

def get_first_available_block() -> GetFirstAvailableBlockResp:

273

"""

274

Get the slot of the lowest confirmed block that has not been purged.

275

276

Returns:

277

GetFirstAvailableBlockResp with slot number

278

"""

279

```

280

281

### Network and Cluster Information

282

283

Retrieve network statistics, validator information, epoch data, and cluster configuration details.

284

285

```python { .api }

286

def get_cluster_nodes() -> GetClusterNodesResp:

287

"""

288

Get information about cluster nodes.

289

290

Returns:

291

GetClusterNodesResp with array of node information

292

"""

293

294

def get_epoch_info(self, commitment: Optional[Commitment] = None) -> GetEpochInfoResp:

295

"""

296

Get current epoch information.

297

298

Parameters:

299

- commitment: Commitment level

300

301

Returns:

302

GetEpochInfoResp with epoch details

303

"""

304

305

def get_slot(self, commitment: Optional[Commitment] = None) -> GetSlotResp:

306

"""

307

Get current slot number.

308

309

Parameters:

310

- commitment: Commitment level

311

312

Returns:

313

GetSlotResp with current slot

314

"""

315

316

def get_version() -> GetVersionResp:

317

"""

318

Get current Solana versions running on the node.

319

320

Returns:

321

GetVersionResp with version information

322

"""

323

324

def get_supply(self, commitment: Optional[Commitment] = None) -> GetSupplyResp:

325

"""

326

Get information about the current supply.

327

328

Parameters:

329

- commitment: Commitment level

330

331

Returns:

332

GetSupplyResp with supply information

333

"""

334

335

def get_recent_performance_samples(self, limit: Optional[int] = None) -> GetRecentPerformanceSamplesResp:

336

"""

337

Get recent performance samples.

338

339

Parameters:

340

- limit: Number of samples to return (max 720)

341

342

Returns:

343

GetRecentPerformanceSamplesResp with performance samples

344

"""

345

346

def get_vote_accounts(self, vote_pubkey: Optional[Pubkey] = None, commitment: Optional[Commitment] = None, keep_unstaked_delinquents: Optional[bool] = None, delinquent_slot_distance: Optional[int] = None) -> GetVoteAccountsResp:

347

"""

348

Get vote accounts information.

349

350

Parameters:

351

- vote_pubkey: Specific vote account to query

352

- commitment: Commitment level

353

- keep_unstaked_delinquents: Include unstaked delinquent validators

354

- delinquent_slot_distance: Slot distance for delinquent determination

355

356

Returns:

357

GetVoteAccountsResp with current and delinquent vote accounts

358

"""

359

```

360

361

### Program Account Queries

362

363

Query accounts owned by specific programs with flexible filtering options and data encoding support.

364

365

```python { .api }

366

def get_program_accounts(self, pubkey: Pubkey, commitment: Optional[Commitment] = None, encoding: str = "base64", data_slice: Optional[DataSliceOpts] = None, filters: Optional[List[Union[int, MemcmpOpts]]] = None) -> GetProgramAccountsResp:

367

"""

368

Get accounts owned by a program.

369

370

Parameters:

371

- pubkey: Program public key

372

- commitment: Commitment level

373

- encoding: Account data encoding

374

- data_slice: Data slice options for partial data

375

- filters: Account filters (data size and memcmp filters)

376

377

Returns:

378

GetProgramAccountsResp with array of accounts

379

"""

380

381

def get_program_accounts_json_parsed(self, pubkey: Pubkey, commitment: Optional[Commitment] = None, filters: Optional[List[Union[int, MemcmpOpts]]] = None) -> GetProgramAccountsMaybeJsonParsedResp:

382

"""

383

Get program accounts with JSON-parsed data when possible.

384

385

Parameters:

386

- pubkey: Program public key

387

- commitment: Commitment level

388

- filters: Account filters

389

390

Returns:

391

GetProgramAccountsMaybeJsonParsedResp with parsed account data

392

"""

393

```

394

395

### Token-Specific Queries

396

397

Specialized queries for SPL Token accounts, balances, and token supply information.

398

399

```python { .api }

400

def get_token_account_balance(self, pubkey: Pubkey, commitment: Optional[Commitment] = None) -> GetTokenAccountBalanceResp:

401

"""

402

Get token account balance.

403

404

Parameters:

405

- pubkey: Token account public key

406

- commitment: Commitment level

407

408

Returns:

409

GetTokenAccountBalanceResp with token balance details

410

"""

411

412

def get_token_accounts_by_owner(self, owner: Pubkey, opts: TokenAccountOpts, commitment: Optional[Commitment] = None) -> GetTokenAccountsByOwnerResp:

413

"""

414

Get token accounts owned by an address.

415

416

Parameters:

417

- owner: Owner public key

418

- opts: Query options (mint or program_id filter)

419

- commitment: Commitment level

420

421

Returns:

422

GetTokenAccountsByOwnerResp with token accounts

423

"""

424

425

def get_token_supply(self, pubkey: Pubkey, commitment: Optional[Commitment] = None) -> GetTokenSupplyResp:

426

"""

427

Get token supply information.

428

429

Parameters:

430

- pubkey: Token mint public key

431

- commitment: Commitment level

432

433

Returns:

434

GetTokenSupplyResp with supply details

435

"""

436

```

437

438

### Economic Information

439

440

Access economic data including fees, inflation rates, rent calculations, and validator performance metrics.

441

442

```python { .api }

443

def get_fee_for_message(self, message: Message, commitment: Optional[Commitment] = None) -> GetFeeForMessageResp:

444

"""

445

Get fee required for a message.

446

447

Parameters:

448

- message: Transaction message

449

- commitment: Commitment level

450

451

Returns:

452

GetFeeForMessageResp with fee in lamports

453

"""

454

455

def get_minimum_balance_for_rent_exemption(self, usize: int, commitment: Optional[Commitment] = None) -> GetMinimumBalanceForRentExemptionResp:

456

"""

457

Get minimum balance needed for rent exemption.

458

459

Parameters:

460

- usize: Account data size in bytes

461

- commitment: Commitment level

462

463

Returns:

464

GetMinimumBalanceForRentExemptionResp with minimum balance in lamports

465

"""

466

467

def get_inflation_rate() -> GetInflationRateResp:

468

"""

469

Get current inflation rate.

470

471

Returns:

472

GetInflationRateResp with inflation rate details

473

"""

474

475

def request_airdrop(self, pubkey: Pubkey, lamports: int, commitment: Optional[Commitment] = None) -> RequestAirdropResp:

476

"""

477

Request SOL airdrop (devnet/testnet only).

478

479

Parameters:

480

- pubkey: Public key to receive airdrop

481

- lamports: Amount of lamports to request

482

- commitment: Commitment level

483

484

Returns:

485

RequestAirdropResp with airdrop transaction signature

486

"""

487

```

488

489

## WebSocket API

490

491

Real-time subscriptions for blockchain events and account changes.

492

493

```python { .api }

494

# WebSocket subscriptions are available through the websocket_api module

495

# for real-time account, program, and signature updates

496

```

497

498

## Types

499

500

```python { .api }

501

class GetBalanceResp:

502

value: int

503

504

class GetAccountInfoResp:

505

value: Optional[Account]

506

507

class Account:

508

lamports: int

509

data: List[str] # [data, encoding]

510

owner: str

511

executable: bool

512

rent_epoch: int

513

514

class SendTransactionResp:

515

value: str # Transaction signature

516

517

class GetLatestBlockhashResp:

518

value: RpcBlockhash

519

520

class RpcBlockhash:

521

blockhash: Hash

522

last_valid_block_height: int

523

524

class DataSliceOpts(NamedTuple):

525

offset: int

526

length: int

527

528

class MemcmpOpts(NamedTuple):

529

offset: int

530

bytes_: str

531

532

class TokenAccountOpts(NamedTuple):

533

mint: Optional[Pubkey] = None

534

program_id: Optional[Pubkey] = None

535

536

class TxOpts(NamedTuple):

537

skip_preflight: bool = False

538

preflight_commitment: Optional[Commitment] = None

539

encoding: str = "base64"

540

max_retries: Optional[int] = None

541

skip_confirmation: bool = False

542

```