> For the complete documentation index, see [llms.txt](https://docs.chainrpc.io/chainrpc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.chainrpc.io/chainrpc/networks/ethereum/how-to/make-requests.md).

# Make requests

The Ethereum network supports requests with HTTP or WebSockets. HTTP requires continual requests to the URL endpoint, whereas WebSockets maintains the connection. You can also make [batch requests](broken://pages/0c9btmBP3ItYSutmi5yF) to the Ethereum network.&#x20;

## curl or wscat

Use [`curl`](https://curl.se) to make the HTTPS requests and [`wscat`](https://www.npmjs.com/package/wscat) for WebSocket requests.

{% hint style="warning" %}
Ensure that you replace`YOUR-API-KEY` with a API key from your chainRPC dashboard.
{% endhint %}

{% tabs %}
{% tab title="HTTPS" %}

```
curl -X POST \
-H "Content-Type: application/json" \
--data '{"jsonrpc": "2.0", "id": 1, "method": "eth_blockNumber", "params": []}' \
"https://eth.chainrpc.io/v3/YOUR-API-KEY"
```

{% endtab %}

{% tab title="Websocket" %}

```
wscat -c wss://eth.chainrpc.io/v3/YOUR-API-KEY
> {"jsonrpc": "2.0", "id": 1, "method": "eth_blockNumber", "params": []}
```

{% endtab %}
{% endtabs %}

## Postman

Call the JSON-RPC methods using [Postman](https://learning.postman.com/docs/getting-started/introduction/).&#x20;

Click the **Run in Postman** button below to fork the collection and make requests.

<div align="left"><figure><img src="/files/toBZ6xVllIfENSGsqsKd" alt=""><figcaption></figcaption></figure></div>

{% hint style="info" %}
Set the correct [variables](https://learning.postman.com/docs/sending-requests/variables/#understanding-variables) for your API key and network before running requests.
{% endhint %}

<figure><img src="/files/NhFJDaPygsKLtgvM1Mig" alt=""><figcaption><p>Ethereum API Postman collection</p></figcaption></figure>

## Web3.js

Save the following script to a file, e.g. `index.js`

```javascript
var Web3 = require('web3');
var provider = 'https://eth.chainrpc.io/v3/<API-KEY>';
var web3Provider = new Web3.providers.HttpProvider(provider);
var web3 = new Web3(web3Provider);
web3.eth.getBlockNumber().then((result) => {
  console.log("Latest Ethereum Block is ",result);
});
```

In a terminal window, run the script with `node index.js`

```
Latest Ethereum Block is  14659509
```

## Ethers

Save the following script to a file, e.g. `index.js`

```javascript
var ethers = require('ethers');
var url = 'https://eth.chainrpc.io/v3/<API-KEY>';
var customHttpProvider = new ethers.providers.JsonRpcProvider(url);
customHttpProvider.getBlockNumber().then((result) => {
    console.log("Current block number: " + result);
});
```

In a terminal window, run the script with `node index.js`

```
Latest Ethereum Block is  14659509
```

## NodeJS

Save the following script to a file, e.g. `index.js`

```javascript
const https = require('https');
const projectId = '<API-KEY>';
const data = JSON.stringify({
    "jsonrpc":"2.0","method":"eth_blockNumber","params": [],"id":1
  })
const options = {
    host: 'eth.chainrpc.io',
    port: 443,
    path: '/v3/' + projectId,
    method: 'POST',
    headers: {
        'Content-Type': 'application/json'
      },
};
const req = https.request(options, res => {
    console.log(`statusCode: ${res.statusCode}`)

    res.on('data', d => {
      process.stdout.write(d)
    })
  })

  req.on('error', error => {
    console.error(error)
  })

  req.write(data)
  req.end()
```

In a terminal window, run the script with `node index.js`

```bash
statusCode: 200
{"jsonrpc":"2.0","id":1,"result":"0xe08e11"} 
```

## Go

1. Initialize a new go module: `go mod init infura`.
2. Install the `go-ethereum` dependency: `go get github.com/ethereum/go-ethereum/rpc`.
3. Save the following script to a file, e.g. `infura.go`.

```go
package main

import (
    "fmt"
    "log"

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

type Block struct {
    Number string
}

func main() {
    client, err := rpc.Dial("https://eth.chainrpc.io/v3/<API-KEY>")
    if err != nil {
        log.Fatalf("Could not connect to Infura: %v", err)
    }

    var lastBlock Block
    err = client.Call(&lastBlock, "eth_getBlockByNumber", "latest", true)
    if err != nil {
        fmt.Println("Cannot get the latest block:", err)
        return
    }

    fmt.Printf("Latest block: %v\n", lastBlock.Number)
}

```

In a terminal window, run the script with `go run infura.go`.

Output:

```
Latest block: 0x....
```

## Python

Run the following code with Python.

```python
from web3 import Web3, HTTPProvider
connection = Web3(HTTPProvider('https://eth.chainrpc.io/v3/<API-KEY>'))
print ("Latest Ethereum block number", connection.eth.blockNumber)
```

Output looks like:

```
Latest Ethereum block number 14659569
```
