Before building payment flows, you need to connect to Solana and understand how to query network data. This guide covers the basics: establishing a connection and using the RPC methods you'll need for payments using the @solana/kit TypeScript SDK and Solana CLI. Additionally, we will cover the basics of using the Solana Explorer to manually verify payments, inspect accounts, and debug issues.
Connecting to Solana
Solana's RPC API is the primary way to programmatically interact with the network. Your RPC URL is effectively an API key to the network.
Do not use public RPC for production
The public endpoints (api.mainnet-beta.solana.com, api.devnet.solana.com)
are rate-limited, have no SLA, and are unsuitable for production payment
flows. Use an RPC provider to secure a private RPC
endpoint for production deployments.
For development and testing, you can use rate-limited public endpoints.
Create an RPC client to interact with the network:
import { createSolanaRpc, createSolanaRpcSubscriptions } from "@solana/kit";const rpc = createSolanaRpc("https://api.mainnet-beta.solana.com");const rpcSubscriptions = createSolanaRpcSubscriptions("wss://api.mainnet-beta.solana.com");
For development, use devnet (https://api.devnet.solana.com) or a local
validator like Surfpool.
Common RPC Methods
Solana's JSON-RPC API exposes methods to query the network. Here are the ones you'll use most for payment flows.
Getting Account Info
All accounts on Solana are addressable by their public key. Use the
getAccountInfo RPC method to fetch
information about any account. The getAccountInfo method returns an
AccountInfo object, which contains the account's public key, SOL balance,
data, and some other metadata.
The data field is a base64 encoded string of the account's data. You can
encode it to bytes using the getBase64Codec method from the @solana/kit
package and then decode it to a readable object using the expected codec (if
known) for the account's data (e.g., getTokenCodec for token accounts).
const accountInfo = await rpc.getAccountInfo(address("7EcDhSYGxXyscszYEp35KHN8vvw3svAuLKTzXwCFLtV"), {encoding: "base64"}).send();const dataBytes = getBase64Codec().encode(accountInfo.value.data);const parsedTokenData = getTokenCodec().decode(dataBytes);console.log(parsedTokenData);
Getting Token Balances
Check a token account's balance using the
getTokenAccountBalance RPC method:
const balance = await rpc.getTokenAccountBalance(tokenAccountAddress).send();console.log(balance.value.uiAmount); // Human-readable (e.g., 100.50)console.log(balance.value.amount); // Base units (e.g., "100500000")
Building Transactions
Every transaction needs a recent blockhash to ensure it is valid (and not
stale). Fetch one before creating a payment transaction using the
getLatestBlockhash RPC method:
const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();
Blockhashes expire after ~60 seconds. Fetch a fresh one immediately before signing and sending.
Checking Transaction Status
Verify a transaction settled using the
getSignatureStatuses RPC method:
const status = await rpc.getSignatureStatuses([signature]).send();const result = status.value[0];// result.confirmationStatus: "processed" | "confirmed" | "finalized"
Getting Transaction Details
Fetch the full details of a confirmed transaction using the
getTransaction RPC method:
const transaction = await rpc.getTransaction(signature, { maxSupportedTransactionVersion: 0 }).send();
Transaction History
Get recent transactions for an address using the
getSignaturesForAddress RPC method:
const signatures = await rpc.getSignaturesForAddress(walletAddress, { limit: 10 }).send();
For comprehensive payment monitoring, see Accept Payments which covers webhooks and real-time transaction detection.
Exploring Public Data
Solana's public ledger means every transaction, token account, and mint is fully auditable. Block explorers let you manually verify payments, inspect accounts, and debug issues without writing code.
What you can look up:
- Verify a payment settled
- Inspect token account balances
- Debug failed transactions
- Look up mint details (supply, decimals, authority)
Common explorers: Solana Explorer, SolanaFM, Solscan, Orb
Example links:
- USDC Token Mint — Supply, markets, holders, and transactions for USDC
- USDC Token Transfer — Details of a USDC payment transaction
- USDG Token Account — A user's USDG balance and transaction history
Is this page helpful?