# eth_hashrate - Berachain RPC Method

Returns the legacy `eth_hashrate` compatibility value on Berachain. Depending on the client behind the endpoint, this call may return a hex quantity like `0x0` or a method-not-found style error.

> **Why Berachain?** Build on the Proof-of-Liquidity L1 with $3.2B+ TVL and innovative three-token economics with Proof-of-Liquidity consensus, three-token model (BERA/BGT/HONEY), $142M funding, and unified validator-DeFi incentive alignment.

> **Note:** Treat `eth_hashrate` as a node-local mining metric and compatibility value. Public endpoints often report `0x0` or reject the method entirely, so it is not a reliable chain-health or consensus signal.

## When to Use This Method

`eth_hashrate` is relevant for DeFi protocol developers, liquidity providers, and teams building yield-optimized applications:

- **Node Diagnostics** - Check whether the connected client reports a legacy hashrate metric
- **Client Capability Checks** - Distinguish between `0x0`, unsupported-method, and method-not-found responses
- **Dashboard Integration** - Display the metric alongside other node status data when it is available

## Best Practices

- Returns `0x0` on proof-of-stake chains (post-Merge) and most modern deployments
- Not relevant for most production environments; treat as informational only
- Do not rely on this method for chain health or consensus signals
- Use eth\_syncing or eth\_blockNumber for reliable node status monitoring

## Request Parameters

This method accepts no parameters.

## Request Example

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

## Response Fields

- `result` (`QUANTITY, required`): Hexadecimal string representing the reported compatibility value when the client exposes the method

## Successful Response

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

## Code Examples

cURL
JavaScript
Python
Go

```bash
curl -X POST https://api-berachain-mainnet.n.dwellir.com/YOUR_API_KEY \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_hashrate",
    "params": [],
    "id": 1
  }'
```

```javascript
// Using fetch
const response = await fetch('https://api-berachain-mainnet.n.dwellir.com/YOUR_API_KEY', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    jsonrpc: '2.0',
    method: 'eth_hashrate',
    params: [],
    id: 1
  })
});

const payload = await response.json();
if (payload.error) {
  console.log('eth_hashrate unsupported:', payload.error.message);
} else {
  console.log('Berachain hashrate:', parseInt(payload.result, 16), 'H/s');
}

// Using ethers.js
import { JsonRpcProvider } from 'ethers';

const provider = new JsonRpcProvider('https://api-berachain-mainnet.n.dwellir.com/YOUR_API_KEY');
try {
  const hashrate = await provider.send('eth_hashrate', []);
  console.log('Berachain hashrate:', parseInt(hashrate, 16), 'H/s');
} catch (error) {
  console.log('eth_hashrate unsupported:', error.message);
}
```

```python
import requests

def get_hashrate():
    response = requests.post(
        'https://api-berachain-mainnet.n.dwellir.com/YOUR_API_KEY',
        json={
            'jsonrpc': '2.0',
            'method': 'eth_hashrate',
            'params': [],
            'id': 1
        }
    )
    payload = response.json()
    if 'error' in payload:
        raise RuntimeError(payload['error']['message'])
    return int(payload['result'], 16)

hashrate = get_hashrate()
print(f'Berachain hashrate: {hashrate} H/s')

# Using web3.py
from web3 import Web3

w3 = Web3(Web3.HTTPProvider('https://api-berachain-mainnet.n.dwellir.com/YOUR_API_KEY'))
try:
    print(f'Berachain hashrate: {w3.eth.hashrate} H/s')
except Exception as exc:
    print(f'eth_hashrate unsupported: {exc}')
```

```go
package main

import (
    "context"
    "encoding/json"
    "fmt"
    "log"

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

func main() {
    client, err := rpc.Dial("https://api-berachain-mainnet.n.dwellir.com/YOUR_API_KEY")
    if err != nil {
        log.Fatal(err)
    }

    var result string
    err = client.CallContext(context.Background(), &result, "eth_hashrate")
    if err != nil {
        log.Println("eth_hashrate unsupported:", err)
        return
    }

    fmt.Printf("Berachain hashrate: %s\n", result)
}
```

## Common Use Cases

### 1. Compatibility-Aware Status Dashboard

Display the reported compatibility value alongside other client status signals without assuming the method is always available:

```javascript
async function getMiningStats(provider) {
  const blockNumber = await provider.getBlockNumber();
  let hashrate = null;
  let supported = true;

  try {
    hashrate = await provider.send('eth_hashrate', []);
  } catch (error) {
    supported = false;
  }

  return {
    supported,
    hashrate: hashrate ? parseInt(hashrate, 16) : null,
    currentBlock: blockNumber
  };
}
```

### 2. Capability Check

Check whether the connected client reports `eth_hashrate` at all:

```javascript
async function getHashrateStatus(provider) {
  try {
    const hashrate = await provider.send('eth_hashrate', []);
    return { supported: true, raw: hashrate, isZero: hashrate === '0x0' };
  } catch (error) {
    return { supported: false, message: error.message };
  }
}

console.log(await getHashrateStatus(provider));
```

zing - retry after delay |
\| -32601 | Method not found | Node client may not support this method |
\| -32005 | Rate limit exceeded | Reduce polling frequency |

## Related Methods

- [`eth_mining`](https://www.dwellir.com/docs/berachain/eth_mining) - Check if the node is actively mining
- [`eth_coinbase`](https://www.dwellir.com/docs/berachain/eth_coinbase) - Get the mining/coinbase address
- [`eth_blockNumber`](https://www.dwellir.com/docs/berachain/eth_blockNumber) - Get the current block height
