# Optimism

Optimism is an EVM equivalent Layer 2 blockchain connected to Ethereum. The Optimism Stack is the standardized, shared, and open-source development stack that makes it easy to spin up your own production-ready Layer 2 blockchain just like Optimism.

### How to Connect to Optimism

You can connect to Optimism using Blockops private API endpoints. Secure your data, speed up your queries, and take control of your API usage with our RPC API endpoint and personalized API keys. [Sign up now](https://beta-app.blockops.network/?callback=api-service) to get your own API key.

### Optimism Mainnnet

To get your API key, create a project using a unique Identifier as the project name and select Optimism from the network options.

<figure><img src="/files/G7ohQGI3zwIz0bUmBPXE" alt=""><figcaption><p>Create Optimism project</p></figcaption></figure>

Open the project to view your api key and rpc endpoints.

<figure><img src="/files/Vbeo0Oshe7KkOmEHyPhO" alt=""><figcaption><p>view Optimism project</p></figcaption></figure>

### Optimism Sepolia

To get your API key, create a project using a unique Identifier as the project name and select Optimism Sepolia from the network options.

<figure><img src="/files/g5XbNQY9A6rCZoy1dRqF" alt=""><figcaption><p>Create Optimism Sepolia project</p></figcaption></figure>

Open the project to view your api key and rpc endpoints.

<figure><img src="/files/L4j8vnX35ASDQp9YVXGm" alt=""><figcaption><p>view Optimism Sepolia project</p></figcaption></figure>

#### Send requests

{% hint style="info" %}
All requests are `POST` requests.
{% endhint %}

{% tabs %}
{% tab title="Https" %}
For Optimism Mainnet

```bash
https://optimism-rpc.blockops.network/?api_key=************
```

For Optimism Sepolia

```bash
https://optimism-sepolia-rpc.blockops.network?api_key=************
```

{% endtab %}

{% tab title="Websocket" %}
For Optimism Mainnet

```bash
wss://optimism-ws.blockops.network?api_key=************
```

For Base Sepolia

```bash
wss://optimism-sepolia-ws.blockops.network?api_key=************
```

{% endtab %}
{% endtabs %}

**Connect via Command Line**

You can connect to the network using websocket or HTTP with your API key in two ways:

* Adding the API key as a query string `?api_key=${APIKEY}`
* Or the request header `-H 'authorization: APIKEY ${APIKEY}'`

**Curl**

For example, the following CURL command can be used to get a block number.

### Optimism Mainnet

{% code overflow="wrap" %}

```bash
curl -H "Content-Type: application/json" -H 'authorization: APIKEY xxxx'  -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' https://optimism-rpc.blockops.network
```

{% endcode %}

### Optimism Sepolia

{% code overflow="wrap" %}

```bash
curl -H "Content-Type: application/json" -H 'authorization: APIKEY xxxx'  -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' https://optimism-sepolia-rpc.blockops.network
```

{% endcode %}

Here is the response you will receive back.

{% code overflow="wrap" %}

```bash
{"jsonrpc":"2.0","id":1,"result":"0x10666b"}
```

{% endcode %}

**Wscat**

If you want to send data requests with WebSockets, you can use several libraries or wscat. You can install and use wscat as follows:

* Download wscat from <https://www.npmjs.com/package/wscat>
* Install wscat by running the following command: `npm install -g wscat`

You can connect to the network with wscat using two options by adding the API key as a query string.

### Optimism Mainnet

{% code overflow="wrap" %}

```bash
wscat -c 'wss://optimism-ws.blockops.network?api_key=*********************'
```

{% endcode %}

Or the request header.

{% code overflow="wrap" %}

```bash
wscat -c 'wss://optimism-ws.blockops.network' --header 'authorization: APIKEY xxxx'
```

{% endcode %}

### Optimism Sepolia

{% code overflow="wrap" %}

```bash
wscat -c 'wss://optimism-sepolia-ws.blockops.network?api_key=*********************'
```

{% endcode %}

Or the request header.

{% code overflow="wrap" %}

```bash
wscat -c 'wss://optimism-sepolia-ws.blockops.network' --header 'authorization: APIKEY xxxx'
```

{% endcode %}

After executing the command, the terminal will display a message indicating that the connection has been enabled successfully.

```bash
Connected (press CTRL+C to quit)
>
```

Then, you can send the following request:

```
{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}
```

{% hint style="info" %}
For more information on the Polkadot network, please see the official [Optimism developer documentation](https://docs.base.org/).
{% endhint %}

Login or set up an account [here](https://beta-app.blockops.network/?callback=api-service) to get started!

#### ***Quick Links***

[Website](https://www.optimism.io/)

[Github](https://github.com/ethereum-optimism)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.blockops.network/networks/supported-networks/optimism.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
