eth_accounts
Returns a list of addresses owned by the client on Avalanche.
Why Avalanche? Build on the fastest smart contract platform with sub-second finality and customizable L1 subnets with sub-second finality, Evergreen subnets for institutions, and partnerships with Franklin Templeton, VanEck, and Bergen County.
Important Note#
On public RPC endpoints like Dwellir, eth_accounts returns an empty array because the node does not hold any private keys. This method is primarily useful for:
- Local development nodes (Ganache, Hardhat, Anvil)
- Private nodes with managed accounts
- Wallet provider connections (MetaMask injects accounts)
When to Use This Method#
eth_accounts is relevant for enterprise developers, RWA tokenizers, and teams building custom blockchain networks in specific scenarios:
- Development Testing — Retrieve test accounts from local nodes
- Wallet Detection — Check if a wallet provider has connected accounts
- Client Verification — Confirm node account access capabilities
Parameters#
This method accepts no parameters.
| Parameter | Type | Required | Description |
|---|---|---|---|
| None | - | - | This method takes no parameters |
Returns#
| Field | Type | Description |
|---|---|---|
| result | Array<DATA> | List of 20-byte account addresses owned by the client |
Return format: Array of 0x prefixed hexadecimal addresses (typically empty for public nodes)
Request#
{
"jsonrpc": "2.0",
"method": "eth_accounts",
"params": [],
"id": 1
}
Response#
Successful Response (Public Node)#
{
"jsonrpc": "2.0",
"id": 1,
"result": []
}
Successful Response (Local Development Node)#
{
"jsonrpc": "2.0",
"id": 1,
"result": [
"0x407d73d8a49eeb85d32cf465507dd71d507100c1",
"0x85d32cf465507dd71d507100c1407d73d8a49eeb"
]
}
Code Examples#
- cURL
- JavaScript
- Python
- Go
curl -X POST https://api-avalanche-mainnet-archive.n.dwellir.com/YOUR_API_KEY/ext/bc/C/rpc \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_accounts",
"params": [],
"id": 1
}'
// Using fetch
const response = await fetch('https://api-avalanche-mainnet-archive.n.dwellir.com/YOUR_API_KEY/ext/bc/C/rpc', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
jsonrpc: '2.0',
method: 'eth_accounts',
params: [],
id: 1
})
});
const { result } = await response.json();
console.log('Accounts:', result);
// Using ethers.js
import { JsonRpcProvider } from 'ethers';
const provider = new JsonRpcProvider('https://api-avalanche-mainnet-archive.n.dwellir.com/YOUR_API_KEY/ext/bc/C/rpc');
const accounts = await provider.listAccounts();
console.log('Accounts:', accounts);
import requests
def get_accounts():
response = requests.post(
'https://api-avalanche-mainnet-archive.n.dwellir.com/YOUR_API_KEY/ext/bc/C/rpc',
json={
'jsonrpc': '2.0',
'method': 'eth_accounts',
'params': [],
'id': 1
}
)
return response.json()['result']
accounts = get_accounts()
print(f'Accounts: {accounts}')
# Using web3.py
from web3 import Web3
w3 = Web3(Web3.HTTPProvider('https://api-avalanche-mainnet-archive.n.dwellir.com/YOUR_API_KEY/ext/bc/C/rpc'))
print(f'Accounts: {w3.eth.accounts}')
package main
import (
"context"
"fmt"
"log"
"github.com/ethereum/go-ethereum/rpc"
)
func main() {
client, err := rpc.Dial("https://api-avalanche-mainnet-archive.n.dwellir.com/YOUR_API_KEY/ext/bc/C/rpc")
if err != nil {
log.Fatal(err)
}
var accounts []string
err = client.CallContext(context.Background(), &accounts, "eth_accounts")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Accounts: %v\n", accounts)
}
Common Use Cases#
1. Development Environment Detection#
Check if running against a development node with test accounts:
async function isDevEnvironment(provider) {
const accounts = await provider.listAccounts();
return accounts.length > 0;
}
const isDev = await isDevEnvironment(provider);
if (isDev) {
console.log('Development environment detected');
}
2. Wallet Connection Check#
Verify wallet provider has connected accounts:
async function checkWalletConnection() {
if (typeof window.ethereum === 'undefined') {
return { connected: false, reason: 'No wallet detected' };
}
const accounts = await window.ethereum.request({
method: 'eth_accounts'
});
return {
connected: accounts.length > 0,
accounts: accounts
};
}
3. Fallback Account Selection#
Use first available account or request connection:
async function getActiveAccount() {
// Check existing connections
let accounts = await window.ethereum.request({
method: 'eth_accounts'
});
// Request connection if no accounts
if (accounts.length === 0) {
accounts = await window.ethereum.request({
method: 'eth_requestAccounts'
});
}
return accounts[0] || null;
}
Error Handling#
Common errors and solutions:
| Error Code | Description | Solution |
|---|---|---|
| -32601 | Method not found | Node may not support this method |
| -32603 | Internal error | Retry with exponential backoff |
async function safeGetAccounts(provider) {
try {
const accounts = await provider.listAccounts();
return { success: true, accounts };
} catch (error) {
if (error.code === -32601) {
console.warn('eth_accounts not supported on this node');
return { success: false, accounts: [], reason: 'unsupported' };
}
throw error;
}
}
Related Methods#
eth_requestAccounts— Request wallet connection (browser wallets)eth_getBalance— Get account balanceeth_getTransactionCount— Get account nonce