eth_accounts - Optimism
Example code for the eth_accounts json-rpc method. Сomplete guide on how to use eth_accounts json-rpc in GetBlock.io Web3 documentation.
This method is used to retrieve addresses that the node controls.
Parameters
None
Request
curl --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"
}'import 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)Response
{
"jsonrpc": "2.0",
"id": "getblock.io",
"result": []
}Response Parameters
id: A unique request identifier, matching theidsent 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
403
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
Last updated
Was this helpful?