# Make requests

## curl or wscat

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](https://paralinker.gitbook.io/paralinker-docs/reference/ethereum-execution-layer/how-to/make-batch-requests) to the Ethereum network.&#x20;

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 the [dashboard](https://dashboard.paralinker.com/).
{% endhint %}

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

<pre class="language-bash"><code class="lang-bash"><strong>curl -X POST \
</strong>-H "Content-Type: application/json" \
--data '{"jsonrpc": "2.0", "id": 1, "method": "eth_blockNumber", "params": []}' \
"https://eth-mainnet.paralinker.com/api/v1/API-KEY"
</code></pre>

{% endtab %}

{% tab title="WebSocket" %}

```bash
wscat -c wss://eth-mainnet.paralinker.com/wss/v1/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.

[![Run in Postman](https://run.pstmn.io/button.svg)](https://app.getpostman.com/run-collection/68294fff62efa65b051f?action=collection%2Fimport)

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

<div align="center"><figure><img src="https://3851559242-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdWnQXn9w0LzfZSfrH31H%2Fuploads%2FoGplwISiEAMSdStNOp5Q%2Fimage.png?alt=media&#x26;token=786518d9-0d6e-4313-b1fd-c931e85b35e2" alt=""><figcaption><p>Ethereum API Postman collection</p></figcaption></figure></div>

## Web3.js

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

```javascript
var Web3 = require('web3');
var provider = 'https://eth-mainnet.paralinker.com/api/v1/<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-mainnet.paralinker.com/api/v1/<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-mainnet.paralinker.com',
    port: 443,
    path: 'api/v1/' + 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 paralinker`.
2. Install the `go-ethereum` dependency: `go get github.com/ethereum/go-ethereum/rpc`.
3. Save the following script to a file, e.g. `paralinker.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-mainnet.paralinker.com/api/v1/<API-KEY>")
    if err != nil {
        log.Fatalf("Could not connect to Mainnet: %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 paralinker.go`.

Output:

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

## Python

Run the following code with Python.

```python
from web3 import Web3, HTTPProvider
connection = Web3(HTTPProvider('https://eth-mainnet.paralinker.com/api/v1/<API-KEY>'))
print ("Latest Ethereum block number", connection.eth.blockNumber)
```

Output looks like:

```
Latest Ethereum block number 14659569
```
