# eth_accounts - Gnosis RPC Method

Returns a list of addresses owned by the client on Gnosis.

> **Why Gnosis?** Build on the prediction market pioneer with $260M+ TVL and xDAI stablecoin-based gas fees with stablecoin gas fees for predictable costs, Shutter MEV protection, 150K+ Safe wallets, and Circles decentralized UBI protocol.

## 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 prediction market builders, DAO tooling developers, and teams building MEV-protected applications 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

## Best Practices

- Most public providers disable this method for security reasons; expect an empty array return
- Use wallet libraries (ethers.js, web3.py) for account management instead of relying on node-side accounts
- An empty array return is normal on managed providers and does not indicate an error condition

## Request Parameters

This method accepts no parameters.

## Request Example

```json
{
  "jsonrpc": "2.0",
  "method": "eth_accounts",
  "params": [],
  "id": 1
}
```

## Response Fields

- `result` (`Array<DATA>, required`): List of 20-byte account addresses owned by the client

## Successful Response

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": []
}
```

## Code Examples

cURL
JavaScript
Python
Go

```bash
curl -X POST https://api-gnosis-mainnet.n.dwellir.com/YOUR_API_KEY \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "eth_accounts",
    "params": [],
    "id": 1
  }'
```

```javascript
// Using fetch
const response = await fetch('https://api-gnosis-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 { result } = await response.json();
console.log('Accounts:', result);

// Using ethers.js
import { JsonRpcProvider } from 'ethers';

const provider = new JsonRpcProvider('https://api-gnosis-mainnet.n.dwellir.com/YOUR_API_KEY');
const accounts = await provider.listAccounts();
console.log('Accounts:', accounts);
```

```python
import requests

def get_accounts():
    response = requests.post(
        'https://api-gnosis-mainnet.n.dwellir.com/YOUR_API_KEY',
        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-gnosis-mainnet.n.dwellir.com/YOUR_API_KEY'))
print(f'Accounts: {w3.eth.accounts}')
```

```go
package main

import (
    "context"
    "fmt"
    "log"

    "github.com/ethereum/go-ethereum/rpc"
)

func main() {
    client, err := rpc.Dial("https://api-gnosis-mainnet.n.dwellir.com/YOUR_API_KEY")
    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:

```javascript
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:

```javascript
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:

```javascript
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;
}
```

## Related Methods

- [`eth_requestAccounts`](https://eips.ethereum.org/EIPS/eip-1102) - Request wallet connection (browser wallets)
- [`eth_getBalance`](https://www.dwellir.com/docs/gnosis/eth_getBalance) - Get account balance
- [`eth_getTransactionCount`](https://www.dwellir.com/docs/gnosis/eth_getTransactionCount) - Get account nonce
