eth_accounts - Polygon

The eth_accounts method returns a list of addresses owned by the client node. Since GetBlock provides access to shared infrastructure rather than personal nodes, this method typically returns an empty array, as account management is not handled by the RPC endpoint.

This method is part of the Polygon JSON-RPC Core API and is useful for checking if any accounts are available for signing transactions directly through the node.

Parameters

  • None

Request

curl

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"
}'

example.js

javascriptimport axios from 'axios';

const url = 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/';

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

axios.post(url, payload, {
    headers: { 'Content-Type': 'application/json' }
})
.then(response => console.log('Accounts:', response.data.result))
.catch(error => console.error(error));

example.py

pythonimport requests
import json

url = "https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/"

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

response = requests.post(url, headers={"Content-Type": "application/json"}, json=payload)
print(response.json())

main.rs

rustuse reqwest::header;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();
    
    let response = client
        .post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
        .header(header::CONTENT_TYPE, "application/json")
        .body(r#"{
            "jsonrpc": "2.0",
            "method": "eth_accounts",
            "params": [],
            "id": "getblock.io"
        }"#)
        .send()
        .await?;
    
    println!("{}", response.text().await?);
    Ok(())
}

Response

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

Response Parameters

FieldTypeDescription
jsonrpcstringJSON-RPC version (2.0)
idstringRequest identifier
resultarrayList of account addresses (typically empty for shared nodes)

Use Case

The eth_accounts method is typically used for:

  • Checking if the connected node manages any accounts
  • Verifying node configuration for account-based operations
  • Determining available signers for transaction signing
  • Development and debugging purposes

Note: When using GetBlock's shared infrastructure, this method will return an empty array since account private keys are not stored on the shared nodes. For transaction signing, use external wallet solutions or the eth_sendRawTransaction method with pre-signed transactions.

Error Handling

Status CodeError MessageCause
403ForbiddenMissing or invalid ACCESS-TOKEN
-32600Invalid RequestMalformed request body

Web3 Integration

ethers.js

javascriptimport { ethers } from 'ethers';

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

const accounts = await provider.send('eth_accounts', []);
console.log('Accounts:', accounts);

viem.js

javascriptimport { createPublicClient, http } from 'viem';
import { polygon } from 'viem/chains';

const client = createPublicClient({
    chain: polygon,
    transport: http('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/')
});

const accounts = await client.request({
    method: 'eth_accounts',
    params: []
});
console.log('Accounts:', accounts);