Solana
准备好在生产环境中调用了吗?
免费套餐涵盖个人项目。按量付费,无需绑卡即可扩展。
Solana
免费套餐涵盖个人项目。按量付费,无需绑卡即可扩展。
Every request to TheRPC's Solana endpoint must carry your API key — it's how the service knows the call is yours and meters it against your plan. The simplest way to authenticate is to put the key directly in the endpoint URL path, as in https://solana.therpc.io/YOUR_API_KEY; if you'd rather keep it out of the URL, you can pass it instead in an Authorization header using the Bearer scheme. This guide walks you through getting a key from your dashboard, placing it correctly for both HTTP and WebSocket connections, securing it, and recognizing the JSON-RPC errors you'll see when authentication fails.
For HTTP calls, place your key in the path of the Solana endpoint so the full URL reads https://solana.therpc.io/YOUR_API_KEY, then POST your JSON-RPC payload to it. If you prefer not to embed the key in the URL, you can additionally send it in the Authorization header with the Bearer scheme (Authorization: Bearer YOUR_API_KEY). The WebSocket PubSub endpoint authenticates the same way — the same key goes in the path of the wss://solana.therpc.io/YOUR_API_KEY connection URL.
When authentication fails, TheRPC replies with a standard JSON-RPC 2.0 error object instead of a result — an error block carrying a numeric code and a human-readable message, like the example below. The usual causes are a missing key (you forgot to fill the path or header), a malformed or invalid key, a key that has been expired or revoked from the dashboard, or a request rejected because you've exceeded your plan's rate limit. Check the message to tell these apart, and re-issue or rotate the key from your dashboard if it's no longer valid.
As a rule, load your key from an environment variable at runtime rather than hardcoding it into your Solana client. Keeping the key in a .env file (excluded from version control) or in your platform's secret store means you can rotate it, swap between mainnet and devnet keys, and share code safely without ever exposing the credential. The examples below read the key into the Solana endpoint URL from the environment in both Node.js and Python.