Optimism (OP)

Optimism is a Layer 2 scaling solution for Ethereum that uses Optimistic Rollup technology to achieve high throughput and low transaction costs while inheriting Ethereum's security. Developed by the Optimism Collective, it enables near-instant transactions by executing them off-chain and posting compressed transaction data to Ethereum mainnet. The network is EVM-equivalent, meaning existing Ethereum smart contracts and tools work seamlessly without modification.

Key Features

  • EVM Equivalence: Full compatibility with Ethereum Virtual Machine, allowing direct deployment of existing Solidity contracts
  • Optimistic Rollups: Transactions are assumed valid by default, with a 7-day challenge period for fraud proofs
  • Low Transaction Fees: Fees typically 10-100x lower than Ethereum mainnet
  • Fast Transactions: Near-instant transaction confirmations (~2 second block time)
  • Ethereum Security: Inherits security from Ethereum L1 through data availability and fraud proofs
  • OP Token: Native governance token for the Optimism Collective
  • Superchain Vision: Part of the broader Superchain ecosystem with shared security and interoperability
  • Bedrock Upgrade: Latest architecture providing improved performance and EVM equivalence
  • Developer-Friendly: Compatible with MetaMask, Hardhat, Foundry, and all standard Ethereum tools

TECHNICAL DISCLAIMER: AUTHORITATIVE JSON-RPC API SPECIFICATION.

GetBlock's RPC API reference documentation is provided exclusively for informational purposes and to optimize the developer experience. The canonical and normative specification for Ethereum Virtual Machine (EVM) JSON-RPC methods is solely maintained and published through the official Ethereum Foundation documentation portal at ethereum.org. For Optimism-specific methods, refer to the official Optimism documentation at docs.optimism.io.

Network Information

PropertyValue
Network NameOptimism Mainnet
Chain ID10
Native CurrencyETH
Decimals18
Block Time~2 seconds
ConsensusOptimistic Rollup
EVM CompatibleYes (EVM Equivalent)
L1 SettlementEthereum Mainnet

Base URL

bashhttps://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/

Supported Networks

NetworkChain IDJSON-RPCWSSFrankfurt, GermanyGraphQL
Mainnet10✅✅✅✅
Sepolia Testnet11155420✅✅✅❌

Quickstart

  1. Setup project

    Create and initialize a new project:

    bashmkdir optimism-api-quickstart
    cd optimism-api-quickstart
    npm init --yes
  2. Install Axios

    bashnpm install axios
  3. Create file

    Create a new file named index.js. This is where you will make your first call.

  4. Set ES module type

    Set the ES module "type": "module" in your package.json.

  5. Add code

    Add the following code to index.js:

    index.js

    javascriptimport axios from 'axios'
    let data = JSON.stringify({
      jsonrpc: "2.0",
      method: "eth_blockNumber",
      params: [],
      id: "getblock.io",
    });
    
    let config = {
      method: "post",
      maxBodyLength: Infinity,
      url: "https://shared.us-east-1.getblock.io/<ACCESS_TOKEN>",
      headers: {
        "Content-Type": "application/json",
      },
      data: data,
    };
    
    axios
      .request(config)
      .then((response) => {
        console.log(JSON.stringify(response.data));
      })
      .catch((error) => {
        console.log(error);
      });
    

    Replace <ACCESS-TOKEN> with your actual access token from GetBlock.

  6. Run the script

    bashnode index.js

    Expected output (example):

    json{
        "jsonrpc": "2.0",
        "id": "getblock.io",
        "result": "0x907de6b"
    }
  1. Set up the project directory

    bashmkdir optimism-api-quickstart
    cd optimism-api-quickstart
  2. Create and activate a virtual environment

    bashpython -m venv venv
    source venv/bin/activate
    
    # On Windows, 
    use venv\Scripts\activate
  3. Install requests

    bashpip install requests
  4. Create script

    Create a file called main.py with the following content:

    main.py

    pythonimport requests
    import json
    
    url = "https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/"
    
    payload = json.dumps({
        "jsonrpc": "2.0",
        "method": "eth_blockNumber",
        "params": [],
        "id": "getblock.io"
    })
    
    headers = {
        'Content-Type': 'application/json'
    }
    
    response = requests.post(url, headers=headers, data=payload)
    print(response.text)

    Replace <ACCESS-TOKEN> with your actual access token from GetBlock.

  5. Run the script

    bashpython main.py

Available API Methods

Account/State Methods

MethodDescription
eth_accountsReturns addresses owned by client
eth_getBalanceReturns the ETH balance of an address
eth_getStorageAtReturns the value at a storage position
eth_getCodeReturns the bytecode at an address
eth_getProofReturns account and storage Merkle proofs
eth_callExecutes a call without creating a transaction

Block Methods

MethodDescription
eth_blockNumberReturns the current block number
eth_getBlockByHashReturns block information by hash
eth_getBlockByNumberReturns block information by number
eth_getBlockTransactionCountByHashReturns transaction count in a block by hash
eth_getBlockTransactionCountByNumberReturns transaction count in a block by number

Transaction Methods

MethodDescription
eth_sendRawTransactionSubmits a signed transaction to the network
eth_getTransactionByHashReturns transaction details by hash
eth_getTransactionByBlockHashAndIndexReturns transaction by block hash and index
eth_getTransactionByBlockNumberAndIndexReturns transaction by block number and index
eth_getTransactionCountReturns the nonce (transaction count) for an address
eth_getTransactionReceiptReturns the receipt of a mined transaction

Gas Methods

MethodDescription
eth_gasPriceReturns the current L2 gas price in wei
eth_estimateGasEstimates gas needed for a transaction

Filter Methods

MethodDescription
eth_getLogsReturns logs matching filter criteria
eth_newFilterCreates a new log filter
eth_newBlockFilterCreates a filter for new blocks
eth_newPendingTransactionFilterCreates a filter for pending transactions
eth_getFilterChangesReturns filter changes since last poll
eth_getFilterLogsReturns all logs matching filter
eth_uninstallFilterRemoves an existing filter

Subscription Methods (WebSocket)

MethodDescription
eth_subscribeCreates a subscription for events
eth_unsubscribeCancels an existing subscription

Uncle Methods

MethodDescription
eth_getUncleByBlockHashAndIndexReturns uncle block by hash and index
eth_getUncleByBlockNumberAndIndexReturns uncle block by number and index
eth_getUncleCountByBlockHashReturns uncle count in a block by hash
eth_getUncleCountByBlockNumberReturns uncle count in a block by number

Network/Chain Methods

MethodDescription
eth_chainIdReturns the chain ID (10)
eth_syncingReturns sync status of the node
net_versionReturns the network ID
net_listeningReturns listening status
net_peerCountReturns number of connected peers
web3_clientVersionReturns the client version
web3_sha3Returns Keccak-256 hash of data
rpc_modulesReturns enabled RPC modules

Support

For technical support and questions:

See Also