eth_accounts - Optimism

This method is used to retrieve addresses that the node controls.

In the context of GetBlock's infrastructure, since no private keys are stored on the nodes, this method will return an empty array. It's primarily useful for compatibility with tools that expect this endpoint to exist.

Parameters

  • None

Request

bashcurl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "eth_accounts",
    "params": [],
    "id": "getblock.io"
}'
pythonimport requests
import json

url = "https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/"
headers = {
    "Content-Type": "application/json"
}
payload = {
    "jsonrpc": "2.0",
    "method": "eth_accounts",
    "params": [],
    "id": "getblock.io"
}

response = requests.post(url, headers=headers, data=json.dumps(payload))

if response.status_code == 200:
    result = response.json().get("result")
    print("eth_accounts result:", result)
else:
    print("Error:", response.status_code, response.text)
javascriptconst axios = require('axios');

const url = "https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/";
const headers = { "Content-Type": "application/json" };

const payload = {
    jsonrpc: "2.0",
    method: "eth_accounts",
    params: [],
    id: "getblock.io"
};

axios.post(url, payload, { headers })
    .then(response => {
        if (response.status === 200) {
            console.log("eth_accounts result:", response.data.result);
        } else {
            console.error("Error:", response.status, response.statusText);
        }
    })
    .catch(error => {
        console.error("Error:", error.response ? error.response.data : error.message);
    });
rust#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::builder()
        .build()?;

    let mut headers = reqwest::header::HeaderMap::new();
    headers.insert("Content-Type", "application/json".parse()?);

    let data = r#"{
    "jsonrpc": "2.0",
     "method": "eth_accounts",
    "params": [],
    "id": "getblock.io"
}"#;

    let json: serde_json::Value = serde_json::from_str(&data)?;

    let request = client.request(reqwest::Method::POST, "https://shared.us-east-1.getblock.io/<ACCESS_TOKEN>")
        .headers(headers)
        .json(&json);

    let response = request.send().await?;
    let body = response.text().await?;

    println!("{}", body);

    Ok(())
}

Response

json{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": []
}

Response Parameters

  • id: A unique request identifier, matching the id sent in the request body.
  • jsonrpc: Specifies the use of JSON-RPC version 2.0.
  • result: An empty array, as GetBlock nodes do not store private keys.

Use Case

The eth_accounts method is commonly used for:

  • Web3 provider initialization
  • Ethereum tool compatibility
  • Client configuration checks

Error handling

Status CodeError MessageCause
403RBAC: access denied Missing or invalid ACCESS_TOKEN.

Integration with Web3

The eth_accounts can help developers to:

  • Identify available signing accounts
  • Auto-select a default wallet in development
  • Validate that a local signer exists
  • Simplify onboarding in testing environments
javascriptimport { ethers } from 'ethers';

// Initialize Ethers provider with GetBlock
const provider = new ethers.JsonRpcProvider(
    'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>'
);

// Using the method through Ethers
async function useEthersMethod() {
    try {
        // Method-specific Ethers implementation
        const result = await provider.send('eth_accounts', []);
        console.log('Result:', result);
        return result;
    } catch (error) {
        console.error('Ethers Error:', error);
        throw error;
    }
}
jsimport { useEffect, useState } from "react";
import { createPublicClient, http } from "viem";
import { optimism } from "viem/chains";
// Create Viem client with GetBlock
const client = createPublicClient({
  chain: optimism,
  transport: http("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>"),
});
// Using the method through Viem
async function Call() {
  try {
 const result = await client.request({
   method: "eth_accounts",
   params: [
   ],
 });
 console.log("Current Block:", result);
 return result;
  }
   catch (error) {
 console.error("Viem Error:", error);
 throw error;
  }
}