Solana
Pronto para usar isso em produção?
O plano gratuito cobre projetos pessoais. O pay-as-you-go escala sem cartão de crédito.
Solana
O plano gratuito cobre projetos pessoais. O pay-as-you-go escala sem cartão de crédito.
The Python ecosystem for Solana pairs two libraries: solana-py supplies the RPC client that talks to the JSON-RPC API, and solders supplies the fast, typed core primitives — Pubkey, Keypair, instructions, messages, and transactions — that are Rust-backed for speed. Install both at once with pip install solana solders.
solana-py ships two clients with the same surface: a synchronous Client for straightforward scripts and an AsyncClient for concurrent, awaitable calls. Both clients build their requests and responses on the solders primitives, so the Pubkey, Keypair, and Transaction types you construct work identically across the sync and async paths.
Construct a Client against the Solana endpoint https://solana.therpc.io/YOUR_API_KEY, optionally pinning a default commitment such as Confirmed. get_balance returns a response whose .value is the lamport balance — divide by 1_000_000_000 (1e9) to convert to SOL — while get_account_info returns the account's owner program, lamports, and data; request base64 encoding when reading accounts with large binary data.
To move SOL, build a transfer instruction with solders' system_program.transfer, fetch a fresh blockhash from get_latest_blockhash (Solana transactions expire quickly, so the blockhash must be recent), assemble the message and signed Transaction, and broadcast it. send_transaction returns a response whose .value is the transaction signature, which you can then confirm by polling its status.
Client and AsyncClient, the Rust-backed solders typed primitives, SPL token helpers, and WebSocket subscription support.AsyncClient mirrors the synchronous Client API method for method, but each call is awaitable — letting you fan out many Solana RPC requests concurrently instead of blocking on each one. It runs inside an asyncio event loop; use it as an async context manager (async with) so the underlying HTTP session is opened and closed cleanly, and drive it with asyncio.run.