Eth.accounts
Returns the accounts the node or wallet holds keys for: the ones it can sign and send from.
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. The examples below leave the transport out.
Send from the first account
Section titled “Send from the first account”The addresses are already validated, so they go straight into another call.
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
Section titled “From a wallet”Over the EIP-1193 transport the result is the accounts the user connected to your app.
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.
Show an address with its checksum
Section titled “Show an address with its checksum”The result is lowercase. Address.checksum gives the EIP-55 form for display.
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
Section titled “Returns”Effect<ReadonlyArray<Address.Address>, Method.Error, Transport>
The accounts, as Address.Address values. The array is empty
when the node holds no key.
Parameters
Section titled “Parameters”None.
Behavior
Section titled “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. TheWalletnamespace exports the same function.
JSON-RPC method
Section titled “JSON-RPC method”eth_accounts