Optimism
Prêt à utiliser cela en production ?
Le niveau gratuit couvre les projets personnels. Le paiement à l'usage évolue sans carte bancaire.
Optimism
Le niveau gratuit couvre les projets personnels. Le paiement à l'usage évolue sans carte bancaire.
Every request to OP Mainnet through TheRPC requires an API key — it authenticates the call against https://optimism.therpc.io/YOUR_API_KEY and links usage to your plan. This guide walks through generating a key from the dashboard, passing it on each request via the Bearer Authorization header, securing it with best practices, loading it from environment variables, and reading the error responses you'll see when authentication fails.
Authorization header.Pass your key in the Authorization header using the Bearer scheme on every OP Mainnet request. There is no session or login step — each JSON-RPC call to https://optimism.therpc.io/YOUR_API_KEY is authenticated on its own, so the header must be present every time, whether you're reading a block or broadcasting a transaction.
When authentication fails on OP Mainnet, TheRPC returns a JSON-RPC error object with a code and a human-readable message instead of a result — for example, code -32001 with "Invalid authentication credentials". The usual causes are a missing Authorization header, a malformed key or wrong header format, an expired or revoked key, or hitting your plan's rate limit. Check the message first, then confirm the key is present, correctly formatted, and still active in the dashboard.
The safest way to use your OP Mainnet key is to load it from an environment variable at runtime rather than writing it directly into your code. Keep it in a .env file that's git-ignored (or in your platform's secret store) and read it through process.env in Node.js or os.getenv in Python, so the key never ends up in your repository or shipped bundles.