# Eth.accounts

Returns the accounts the node or wallet holds keys for: the ones it can sign and send from.

## Usage

```ts
import { Effect } from "effect";
import { FetchHttpClient } from "effect/http";
import { Transport } from "@ethect/core";
import { Eth } from "@ethect/core/rpc";

const accounts = await Eth.accounts().pipe(
  Effect.provide(Transport.http("http://127.0.0.1:8545")),
  Effect.provide(FetchHttpClient.layer),
  Effect.runPromise,
);
// [
//   "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
//   "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",
//   … anvil's ten development accounts
// ]
```

The call works over every [transport](https://ethect.dev/guides/transports/). The examples below leave the
transport out.

### Send from the first account

The addresses are already validated, so they go straight into another call.

```ts
import { Effect } from "effect";
import { Eth } from "@ethect/core/rpc";

const hash = Effect.gen(function* () {
  const [from, to] = yield* Eth.accounts();
  if (from === undefined || to === undefined) return yield* Effect.fail("no account");
  return yield* Eth.sendTransaction({ from, to, value: 1n });
});
```

### From a wallet

Over the [EIP-1193 transport](https://ethect.dev/reference/transport/eip1193/) the result is the accounts the
user connected to your app.

```ts
import { Effect } from "effect";
import { type Eip1193, Transport } from "@ethect/core";
import { Eth } from "@ethect/core/rpc";

// The wallet's EIP-1193 provider: `window.ethereum`, or the one a wallet SDK returns.
declare const provider: Eip1193.Provider;

const connected = await Eth.accounts().pipe(
  Effect.provide(Transport.eip1193(provider)),
  Effect.runPromise,
);
```

It returns what is already connected. To ask the user to connect accounts, use
[`Wallet.requestAccounts`](https://ethect.dev/rpc/wallet/request-accounts/).

### Show an address with its checksum

The result is lowercase. `Address.checksum` gives the EIP-55 form for display.

```ts
import { Effect } from "effect";
import { Address } from "@ethect/core";
import { Eth } from "@ethect/core/rpc";

const display = Eth.accounts().pipe(
  Effect.map((accounts) => accounts.map(Address.checksum)),
);
// ["0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266", …]
```

## Returns

[`Effect<ReadonlyArray<Address.Address>, Method.Error, Transport>`](https://ethect.dev/rpc/method/#calling-a-method)

The accounts, as [`Address.Address`](https://ethect.dev/reference/primitives/address/) values. The array is empty
when the node holds no key.

## Parameters

None.

## Behavior

- **Lowercase addresses.** Each address is decoded to its lowercase form, so two of them can be
  compared with `===`.
- **Keys the node holds, not accounts that exist.** anvil answers its ten development accounts.
  A node that holds no key answers `[]`.
- **Also `Wallet.accounts`.** The [`Wallet`](https://ethect.dev/rpc/wallet/) namespace exports the same
  function.

## JSON-RPC method

`eth_accounts`
