eth_accounts
Returns a list of addresses owned by the client.
Node Wallet Required
This method returns accounts managed by the node. For most RPC providers, this returns an empty array as they don't manage private keys. Use wallet software to manage accounts.
When to Use This Method
Use eth_accounts
to:
- List Node Accounts - Get addresses managed by the node
- Wallet Integration - Check available accounts in browser wallets
- Account Discovery - Find accounts for transaction signing
- Development Testing - List test accounts in development nodes
Parameters
This method accepts no parameters.
{
"jsonrpc": "2.0",
"method": "eth_accounts",
"params": [],
"id": 1
}
Returns
Array of DATA
- Array of 20-byte account addresses owned by the client.
- Type: Array of strings
- Format: Hexadecimal addresses with
0x
prefix - Size: Each address is 20 bytes (40 hex characters)
Implementation Examples
- cURL
- JavaScript
- Python
curl -X POST https://api-xdc-mainnet.n.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-xdc-mainnet.n.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('Available accounts:', data.result);
// Using ethers.js
import { ethers } from 'ethers';
const provider = new ethers.JsonRpcProvider('https://api-xdc-mainnet.n.dwellir.com/YOUR_API_KEY');
const accounts = await provider.listAccounts();
console.log('Node accounts:', accounts);
// Using web3.js
import Web3 from 'web3';
const web3 = new Web3('https://api-xdc-mainnet.n.dwellir.com/YOUR_API_KEY');
const accounts = await web3.eth.getAccounts();
console.log('Available accounts:', accounts);
// Browser wallet integration
if (window.ethereum) {
const accounts = await window.ethereum.request({
method: 'eth_accounts'
});
console.log('Wallet accounts:', accounts);
}
import requests
import json
# Using requests
url = 'https://api-xdc-mainnet.n.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))
result = response.json()
print('Available accounts:', result['result'])
# Using web3.py
from web3 import Web3
w3 = Web3(Web3.HTTPProvider('https://api-xdc-mainnet.n.dwellir.com/YOUR_API_KEY'))
accounts = w3.eth.accounts
print('Node accounts:', accounts)
Example Response
{
"jsonrpc": "2.0",
"id": 1,
"result": []
}
Empty Response
Most public RPC endpoints return an empty array as they don't manage private keys. This is expected behavior for security reasons.
Omnichain Account Management
xdc enables unique cross-chain account interactions:
Universal Account Model
// xdc allows one account to interact with multiple chains
const zetaAccount = '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb8';
// This single account can:
// - Hold assets from multiple chains
// - Execute cross-chain transactions
// - Deploy omnichain smart contracts
Cross-Chain Account Detection
async function detectOmnichainAccounts() {
// Check for xdc accounts
const zetaAccounts = await provider.listAccounts();
// Check connected chain accounts
const connectedChains = await zetaConnector.getConnectedChains();
const allAccounts = {};
for (const chain of connectedChains) {
allAccounts[chain.name] = await chain.getAccounts();
}
return {
xdc: zetaAccounts,
connected: allAccounts
};
}
Common Use Cases
1. Wallet Connection Check
async function checkWalletConnection() {
const accounts = await web3.eth.getAccounts();
if (accounts.length === 0) {
console.log('No wallet connected');
return false;
}
console.log('Connected account:', accounts[0]);
return true;
}
2. Account Authorization for Omnichain Contracts
async function authorizeOmnichainAccount() {
// Request account access for xdc
const accounts = await window.ethereum.request({
method: 'eth_requestAccounts'
});
if (accounts.length > 0) {
// Set up omnichain capabilities
const omnichainContract = new ethers.Contract(
OMNICHAIN_CONTRACT_ADDRESS,
OMNICHAIN_ABI,
provider
);
// Authorize cross-chain operations
await omnichainContract.authorizeAccount(accounts[0]);
console.log('Account authorized for cross-chain operations');
}
}
3. Multi-Wallet Support
class OmnichainWalletManager {
async getAllAccounts() {
const accounts = {
metamask: [],
walletConnect: [],
xdc: []
};
// Check MetaMask
if (window.ethereum) {
accounts.metamask = await window.ethereum.request({
method: 'eth_accounts'
});
}
// Check WalletConnect
if (this.walletConnectProvider) {
accounts.walletConnect = await this.walletConnectProvider.accounts;
}
// Check xdc native
accounts.xdc = await provider.send('eth_accounts', []);
return accounts;
}
async selectAccount(address) {
// Set active account for omnichain operations
this.activeAccount = address;
console.log('Active omnichain account:', address);
}
}
4. Development Environment Setup
// For local xdc development
async function setupDevAccounts() {
const provider = new ethers.JsonRpcProvider('http://localhost:8545');
// Get development accounts
const accounts = await provider.listAccounts();
if (accounts.length > 0) {
console.log('Development accounts available:');
accounts.forEach((account, index) => {
console.log(` Account ${index}: ${account}`);
});
// Fund accounts for testing
const faucet = new ethers.Contract(FAUCET_ADDRESS, FAUCET_ABI, provider);
for (const account of accounts) {
await faucet.drip(account);
console.log(`Funded ${account} with test ZETA`);
}
}
}
Account Types on xdc
External Accounts (EOA)
- Standard Ethereum-compatible accounts
- Can initiate cross-chain transactions
- Hold ZETA tokens for gas
Omnichain Smart Contract Accounts
- Deploy once, interact with all chains
- Can hold and manage multi-chain assets
- Execute complex cross-chain logic
TSS (Threshold Signature Scheme) Accounts
- Used for xdc's cross-chain messaging
- Managed by validator network
- Enable trustless cross-chain operations
Best Practices
- Never expose private keys through RPC
- Use hardware wallets for production
- Implement proper account authorization flows
- Cache account lists to reduce RPC calls
- Handle account changes in real-time
- Support multiple wallet providers
Error Codes
Code | Message | Description |
---|---|---|
-32600 | Invalid Request | The JSON sent is not valid |
-32601 | Method not found | Method doesn't exist |
-32602 | Invalid params | Invalid parameters |
-32603 | Internal error | Internal JSON-RPC error |
Account Security
Never Store Private Keys
// ❌ NEVER DO THIS
const privateKey = '0x...'; // Never hardcode
// ✅ DO THIS
// Use wallet providers or secure key management
const signer = await provider.getSigner();
Implement Proper Authorization
async function requestAccounts() {
try {
// Request account access
const accounts = await window.ethereum.request({
method: 'eth_requestAccounts'
});
// Verify chain ID for xdc
const chainId = await window.ethereum.request({
method: 'eth_chainId'
});
if (parseInt(chainId, 16) !== 7000) {
throw new Error('Please connect to xdc mainnet');
}
return accounts;
} catch (error) {
console.error('Account access denied:', error);
throw error;
}
}
Related Methods
eth_requestAccounts
- Request account access from a connected walleteth_sign
- Sign messages with the selected accounteth_sendRawTransaction
- Broadcast signed transactions- eth_getBalance - Check account balance