⚠️Blast API (blastapi.io) ends Oct 31. Migrate to Dwellir and skip Alchemy's expensive compute units.
Switch Today →
Skip to main content

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 -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
}'

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

  1. Never expose private keys through RPC
  2. Use hardware wallets for production
  3. Implement proper account authorization flows
  4. Cache account lists to reduce RPC calls
  5. Handle account changes in real-time
  6. Support multiple wallet providers

Error Codes

CodeMessageDescription
-32600Invalid RequestThe JSON sent is not valid
-32601Method not foundMethod doesn't exist
-32602Invalid paramsInvalid parameters
-32603Internal errorInternal 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;
}
}
  • eth_requestAccounts - Request account access from a connected wallet
  • eth_sign - Sign messages with the selected account
  • eth_sendRawTransaction - Broadcast signed transactions
  • eth_getBalance - Check account balance