# Make your first RPC request

Source: https://docs.graphops.xyz/rpc/getting-started

Confirm that your application can reach GraphOps RPC by reading the latest Ethereum block number.
Use curl or your preferred EVM client library.

**Expected result:** the current block number: a hex quantity from curl, a decimal number from the
client libraries.

## Prerequisites

* A GraphOps Platform account.
* An organization with access to RPC.
* An Owner or Developer role to create an API key that includes RPC, or such a key supplied by
your team.
* Ethereum mainnet endpoint access.

The endpoint path ends in the EVM chain ID. These examples use Ethereum mainnet (`1`) and read your
API key from the `GRAPHOPS_API_KEY` environment variable. For other endpoints, see
[Supported networks](./networks).

### Create an API key \[#create-an-api-key]

[Create API key](https://platform.graphops.xyz/organizations/current/api-keys)

Choose your organization and create a query key that includes RPC.

Store the plaintext key in your secret manager. The platform only shows the plaintext key at
creation or rotation time.

### Choose an endpoint \[#choose-an-endpoint]

Choose the network endpoint. This guide uses Ethereum mainnet:

```text
https://rpc.graphops.xyz/v1/evm/1

```

Endpoint preview. Replace placeholders with your identifier and API key before making requests.

```text
https://rpc.graphops.xyz/v1/evm/1
Authorization: Bearer <GRAPHOPS_API_KEY>
```

[Get query endpoint](https://platform.graphops.xyz/organizations/current/overview/endpoint?product=rpc&networkId=eip155%3A1)
[Supported networks](/rpc/networks)

Mainnet and testnet endpoints use the same authentication model. See
[Authentication](./authentication) for header and route-token options.

### Read the latest block \[#read-the-latest-block]

Run an `eth_blockNumber` request against the Ethereum mainnet endpoint.

CLI · curl

Prerequisites

1. Set GRAPHOPS\_API\_KEY to your GraphOps API key.

[Example project](/examples/rpc.api.sh-6.tar.gz)

```sh
curl --fail-with-body --silent --show-error "https://rpc.graphops.xyz/v1/evm/1" \
  -H "Authorization: Bearer ${GRAPHOPS_API_KEY}" \
  -H "Content-Type: application/json" \
  --data '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "eth_blockNumber",
    "params": []
  }'

```

Output

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x191161d"
}
```

JSON-RPC version

Matches the id you sent

Latest block in decimal: 26,285,597

TypeScript · viem

Prerequisites

1. Install Node.js.

2. Install tsx and viem. `npm install tsx viem`

3. Set GRAPHOPS\_API\_KEY to your GraphOps API key.

Tested with Node.js 24.22.1, tsx 4.23.15, viem 2.57.10.

[Example project](/examples/rpc.api.ts-7.tar.gz)

```typescript
import { createPublicClient, http } from "viem";
import { mainnet } from "viem/chains";

const client = createPublicClient({
  chain: mainnet,
  transport: http("https://rpc.graphops.xyz/v1/evm/1", {
    fetchOptions: {
      headers: {
        Authorization: `Bearer ${process.env.GRAPHOPS_API_KEY}`,
      },
    },
  }),
});

const blockNumber = await client.getBlockNumber();
console.log(blockNumber.toString());

```

Output

```json
26285599
```

Latest block in decimal: 26,285,599

Go · ethclient

Prerequisites

1. Install Go.

2. Install github.com/ethereum/go-ethereum. `go get github.com/ethereum/go-ethereum`

3. Set GRAPHOPS\_API\_KEY to your GraphOps API key.

Tested with Go 1.26.0, github.com/ethereum/go-ethereum v1.17.7.

[Example project](/examples/rpc.api.go-12.tar.gz)

```go
package main

import (
	"context"
	"fmt"
	"log"
	"os"

	"github.com/ethereum/go-ethereum/ethclient"
	"github.com/ethereum/go-ethereum/rpc"
)

func main() {
	ctx := context.Background()
	rpcClient, err := rpc.DialOptions(ctx, "https://rpc.graphops.xyz/v1/evm/1",
		rpc.WithHeader("Authorization", "Bearer "+os.Getenv("GRAPHOPS_API_KEY")))
	if err != nil {
		log.Fatal(err)
	}
	client := ethclient.NewClient(rpcClient)
	defer client.Close()

	blockNumber, err := client.BlockNumber(ctx)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(blockNumber)
}

```

Output

```json
26285612
```

Latest block in decimal: 26,285,612

Rust · alloy

Prerequisites

1. Install Rust.

2. Install alloy, reqwest, and tokio. `cargo add alloy reqwest tokio -F alloy/provider-ws -F alloy/sol-types -F alloy/contract -F reqwest/json -F tokio/macros -F tokio/rt-multi-thread`

3. Set GRAPHOPS\_API\_KEY to your GraphOps API key.

Tested with Rust 1.98.1, alloy 2.5.0, reqwest 0.13.5, tokio 1.48.0.

[Example project](/examples/rpc.api.rust-13.tar.gz)

```rust
use alloy::providers::{Provider, ProviderBuilder};
use alloy::rpc::client::RpcClient;
use alloy::transports::http::Http;
use reqwest::header::{HeaderMap, AUTHORIZATION};
use std::{env, error::Error};

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let mut headers = HeaderMap::new();
    headers.insert(
        AUTHORIZATION,
        format!("Bearer {}", env::var("GRAPHOPS_API_KEY")?).parse()?,
    );
    let http = reqwest::Client::builder()
        .default_headers(headers)
        .build()?;
    let provider = ProviderBuilder::new().connect_client(RpcClient::new(
        Http::with_client(http, "https://rpc.graphops.xyz/v1/evm/1".parse()?),
        false,
    ));

    let block_number = provider.get_block_number().await?;
    println!("{block_number}");
    Ok(())
}

```

Output

```json
26285610
```

Latest block in decimal: 26,285,610

Python · web3.py

Prerequisites

1. Install Python.

2. Install web3. `python -m pip install web3`

3. Set GRAPHOPS\_API\_KEY to your GraphOps API key.

Tested with Python 3.12.12, web3 8.0.0.

[Example project](/examples/rpc.api.python-9.tar.gz)

```python
import os
from web3 import Web3

w3 = Web3(
    Web3.HTTPProvider(
        "https://rpc.graphops.xyz/v1/evm/1",
        request_kwargs={
            "headers": {
                "Authorization": f"Bearer {os.environ['GRAPHOPS_API_KEY']}",
            },
        },
    )
)

print(w3.eth.block_number)

```

Output

```json
26285600
```

Latest block in decimal: 26,285,600

## Next steps

* [Fetch logs](./guides/fetch-logs): Read the USDC `Transfer` logs from one block and keep larger scans bounded.
* [Read contract state](./guides/read-contract-state): Call a contract with `eth_call` at a block you choose.
* [Authentication](./authentication): Choose between header and route-token authentication before you deploy.
* [Usage and limits](./usage-and-limits): Check credit rates and shared limits before sending production traffic.