eth_accounts
Returns a list of addresses owned by the client.
When to Use This Method
eth_accounts
is used for:
- Wallet Integration - Retrieve available accounts from connected wallets
- Account Management - List all accounts controlled by the node
- DApp Authentication - Verify user has accounts available
- Multi-Account Support - Handle multiple account scenarios
info
This method typically returns an empty array []
on public RPC endpoints as they don't manage private keys. It's primarily used with local nodes or wallet-injected providers.
Parameters
This method accepts no parameters.
{
"jsonrpc": "2.0",
"method": "eth_accounts",
"params": [],
"id": 1
}
Returns
Array
- Array of account addresses owned by the client.
- Type: Array of strings
- Format: Ethereum-compatible addresses (0x prefixed, 20 bytes)
- Example:
["0x407d73d8a49eeb85d32cf465507dd71d507100c1"]
Implementation Examples
- cURL
- JavaScript
- Python
curl -X POST https://api-tron-jsonrpc.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_accounts",
"params": [],
"id": 1
}'
// Using fetch
const response = await fetch('https://api-tron-jsonrpc.dwellir.com/YOUR_API_KEY', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
jsonrpc: '2.0',
method: 'eth_accounts',
params: [],
id: 1,
}),
});
const data = await response.json();
console.log('Accounts:', data.result);
// Using ethers.js
import { ethers } from 'ethers';
const provider = new ethers.JsonRpcProvider('https://api-tron-jsonrpc.dwellir.com/YOUR_API_KEY');
const accounts = await provider.listAccounts();
console.log('Available accounts:', accounts);
import requests
import json
# Using requests library
url = 'https://api-tron-jsonrpc.dwellir.com/YOUR_API_KEY'
headers = {'Content-Type': 'application/json'}
payload = {
'jsonrpc': '2.0',
'method': 'eth_accounts',
'params': [],
'id': 1
}
response = requests.post(url, headers=headers, data=json.dumps(payload))
accounts = response.json().get('result', [])
print(f'Accounts: {accounts}')
# Using web3.py
from web3 import Web3
w3 = Web3(Web3.HTTPProvider('https://api-tron-jsonrpc.dwellir.com/YOUR_API_KEY'))
accounts = w3.eth.accounts
print(f'Available accounts: {accounts}')
Example Response
{
"jsonrpc": "2.0",
"id": 1,
"result": []
}
note
Public RPC endpoints typically return an empty array since they don't manage private keys. To get accounts, use wallet-injected providers or local nodes with unlocked accounts.
Common Use Cases
1. Wallet Connection Check
async function checkWalletConnection() {
const accounts = await provider.send('eth_accounts', []);
if (accounts.length === 0) {
console.log('No wallet connected');
return false;
}
console.log(`Connected with account: ${accounts[0]}`);
return true;
}
2. Multi-Account Selection
async function selectAccount() {
const accounts = await provider.send('eth_accounts', []);
if (accounts.length > 1) {
// Show account selector UI
return await showAccountSelector(accounts);
}
return accounts[0];
}
3. Account Change Detection
let currentAccount = null;
async function monitorAccountChange() {
const accounts = await provider.send('eth_accounts', []);
const newAccount = accounts[0] || null;
if (newAccount !== currentAccount) {
currentAccount = newAccount;
console.log('Account changed to:', currentAccount);
// Handle account change
}
}
Error Codes
Code | Message | Description |
---|---|---|
-32600 | Invalid Request | The JSON sent is not a valid Request object |
-32601 | Method not found | The method eth_accounts is not available |
-32602 | Invalid params | Invalid method parameters |
-32603 | Internal error | Internal JSON-RPC error |
Related Methods
- eth_getBalance - Get account balance
- eth_getTransactionCount - Get account nonce