Optimism
准备好在生产环境中调用了吗?
免费套餐涵盖个人项目。按量付费,无需绑卡即可扩展。
Optimism
免费套餐涵盖个人项目。按量付费,无需绑卡即可扩展。
This page covers the OP Mainnet operations developers reach for first: reading the latest block and an account's ETH balance, looking up transactions and their receipts, fetching blocks by number or hash, calling smart contracts, checking network and sync status, and pulling gas price and nonce before sending a transaction. Because OP Mainnet is bytecode-equivalent with Ethereum, each example runs against https://optimism.therpc.io/YOUR_API_KEY using the exact request shapes you already know.
Two reads form the foundation of almost every OP Mainnet integration: eth_blockNumber, which returns the height of the latest sequenced block (a fresh one roughly every 2 seconds), and eth_getBalance, which returns an account's ETH balance. The balance comes back as a hex value in wei, so divide by 10^18 to convert it to ETH before showing it to a user.
Two reads cover transaction lookups on OP Mainnet. eth_getTransactionByHash returns a transaction's details and tells you whether it has been mined — a null blockNumber means it's still pending in the pool. eth_getTransactionReceipt returns the full receipt once the transaction is included, including its success status, the block it landed in, gas used, and the emitted event logs.
You can fetch an OP Mainnet block two ways: eth_getBlockByNumber takes a block height (or a tag like latest), and eth_getBlockByHash takes the block's hash. Both accept a boolean second parameter: pass true to get full transaction objects embedded in the block, or false to get just the list of transaction hashes — a lighter response when you only need the header and tx list.
Two methods cover reading from smart contracts on OP Mainnet. eth_call executes a contract's view or pure function against a given block without sending a transaction or spending gas — ideal for reading a token balance from a Velodrome or Synthetix contract. eth_getCode returns the deployed bytecode at an address, which lets you confirm a contract exists and distinguish a contract account from a plain wallet.
Two checks confirm you're talking to a healthy OP Mainnet node. net_version returns the network's chain ID as a string — "10" for OP Mainnet — which is a quick way to confirm your client is pointed at the right Superchain network. eth_syncing reports the node's sync state, returning false when the node is fully caught up or a progress object while it's still syncing.
Before sending a transaction on OP Mainnet, two reads prepare the values you need. eth_gasPrice returns the current gas price in wei — typically low on this OP Stack L2 thanks to ~2-second blocks and L1 settlement — which helps you set a sensible fee. eth_getTransactionCount returns an address's nonce, the count of transactions it has already sent. The nonce sequences transactions from an address: each new transaction must use the next nonce in order, or it will be rejected or stuck.
requests against the endpoint; see the Python guide.