eth_accounts - zkSync RPC Method
Returns a list of addresses owned by the client on zkSync Era. Typically returns an empty array on public RPC endpoints.
Returns a list of addresses owned by the client on zkSync Era.
Why zkSync? Build on Matter Labs' flagship zkEVM powering the Elastic Network of interoperable hyperchains with ZK Stack modular framework, hyperchain interoperability, native account abstraction, and $1.9B in tokenized real-world assets.
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 ZK developers, RWA tokenization teams, and builders launching custom L2/L3 chains 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
Code Examples
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
eth_getTransactionCount
Get the number of transactions sent from an address (nonce) on zkSync Era. Essential for nonce management, transaction signing, and detecting stuck transactions.
eth_sendRawTransaction
Submit signed transactions to zkSync Era. Essential for broadcasting transactions for RWA tokenization ($1.9B, 25% market share), hyperchain deployment via ZK Stack, and cross-chain DeFi.