Skip to content

Wallet methods (Wallet)

The wallet namespace: what a wallet serves through an EIP-1193 provider such as window.ethereum. Each export is one JSON-RPC method as a typed function, and the eth_ methods a wallet shares with a node are re-exported from Eth.

import { Effect } from "effect";
import { type Eip1193, Transport } from "@ethect/core";
import { Wallet } 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 program = Effect.gen(function* () {
const accounts = yield* Wallet.requestAccounts();
const chainId = yield* Wallet.chainId();
return { accounts, chainId };
});
const session = await program.pipe(
Effect.provide(Transport.eip1193(provider)),
Effect.runPromise,
);

A method takes its JSON-RPC params in order and returns an Effect of the decoded result. It runs over Transport.eip1193, which turns the provider into a transport: see Wallets.

The name is the wire name without its prefix: wallet_sendCalls is Wallet.sendCalls, eth_requestAccounts is Wallet.requestAccounts and personal_sign is Wallet.personalSign. The exception is wallet_sendTransaction, which is Wallet.walletSendTransaction because Wallet.sendTransaction is eth_sendTransaction.

Method JSON-RPC Returns Description
requestAccounts eth_requestAccounts Address[] Asks the user to connect accounts to the app (EIP-1102).
connect wallet_connect { accounts } Connects accounts and asks for capabilities in the same prompt (ERC-7846, a draft).
disconnect wallet_disconnect void Disconnects the app’s accounts (ERC-7846, a draft).
addSubAccount wallet_addSubAccount SubAccount Has the wallet create or track an account that its main account owns (ERC-7895, a draft).
getPermissions wallet_getPermissions Permission[] The permissions the user gave the app (EIP-2255).
requestPermissions wallet_requestPermissions Permission[] Asks the user for permissions (EIP-2255).
revokePermissions wallet_revokePermissions void Gives permissions back.
grantPermissions wallet_grantPermissions PermissionGrant Asks the user to let a session key or account act for them (ERC-7715, a draft).
Method JSON-RPC Returns Description
switchEthereumChain wallet_switchEthereumChain void Asks the wallet to make a chain its active one (EIP-3326).
addEthereumChain wallet_addEthereumChain void Suggests a chain for the wallet to add (EIP-3085).
watchAsset wallet_watchAsset boolean Suggests a token for the wallet to track (EIP-747).
getAssets wallet_getAssets assets by chain The assets the wallet holds for an account (ERC-7811, a draft).
Method JSON-RPC Returns Description
personalSign personal_sign Hex Signs a message with an account’s key (EIP-191).
walletSendTransaction wallet_sendTransaction Hash eth_sendTransaction under the name some wallets serve it by.
Method JSON-RPC Returns Description
sendCalls wallet_sendCalls { id } Asks the wallet to send a batch of calls (EIP-5792).
getCallsStatus wallet_getCallsStatus CallsStatus Where a batch stands, with its receipts once included.
showCallsStatus wallet_showCallsStatus void Has the wallet show the user where a batch stands.
getCapabilities wallet_getCapabilities capabilities by chain What the wallet can do for an account.

A wallet answers some eth_ methods itself. Wallet re-exports their definitions from Eth: they are the same functions, not copies.

import { Eth, Wallet } from "@ethect/core/rpc";
const same = Wallet.chainId === Eth.chainId; // true

Each one is documented on its Eth page.

Method JSON-RPC Returns Description
accounts eth_accounts Address[] The accounts the node or wallet holds keys for.
chainId eth_chainId number The chain id of the network.
estimateGas eth_estimateGas bigint The gas a transaction would need.
fillTransaction eth_fillTransaction { raw, tx } Fills in what a request leaves out, without sending it.
sendRawTransaction eth_sendRawTransaction Hash Sends a signed, encoded transaction.
sendRawTransactionSync eth_sendRawTransactionSync Receipt The same, and waits for the receipt.
sendTransaction eth_sendTransaction Hash Signs and sends a transaction from an account the node or wallet holds.
sign eth_sign Hex Signs a message with an account’s key.
signTransaction eth_signTransaction Hex Signs a transaction without sending it.
signTypedDataV4 eth_signTypedData_v4 Hex Signs EIP-712 typed data.
syncing eth_syncing false or progress Whether the node is syncing, and how far it is.

The other Eth methods are not re-exported. They run over the same transport: import Eth for them.

  • Nothing to return. disconnect, revokePermissions, switchEthereumChain, addEthereumChain and showCallsStatus have no result. Whatever the wallet answers is ignored, and the effect succeeds with void.
  • Drafts. connect, disconnect, addSubAccount, grantPermissions and getAssets follow ERCs that are still drafts. Their shapes can change, and a wallet may not serve them.
  • A node is not a wallet. anvil 1.9 serves requestAccounts, personalSign and sendTransaction, and answers every wallet_ method with the reason MethodNotFound.
  • Events are streams. The accounts and the chain of a wallet change without a call. Follow them with Eip1193.accountsChanged and Eip1193.chainChanged: see Eip1193.

A wallet rejects a call with a JSON-RPC error object. It becomes an RpcError whose reason names the code.

import { Effect } from "effect";
import { Wallet } from "@ethect/core/rpc";
const accounts = Wallet.requestAccounts().pipe(
// the user closed the prompt
Effect.catchReason("RpcError", "UserRejectedRequest", () =>
Effect.succeed([]),
),
);

The reasons a wallet answers with:

Reason Code When
UserRejectedRequest 4001 the user rejected the request
Unauthorized 4100 the method or the account has not been authorized by the user
UnsupportedMethod 4200 the provider does not support the method
Disconnected 4900 the provider is disconnected from all chains
ChainDisconnected 4901 the provider is not connected to the requested chain
UnrecognizedChain 4902 the wallet does not know the chain
UnsupportedNonOptionalCapability 5700 the wallet lacks a capability that was not marked optional
UnsupportedChainId 5710 the wallet does not support the chain of a batch
DuplicateId 5720 a batch was already sent with this id
UnknownBundleId 5730 no batch was sent with this id
BundleTooLarge 5740 the batch is too large for the wallet
AtomicReadyWalletRejectedUpgrade 5750 the wallet could run the batch atomically after an upgrade, and the user rejected the upgrade
AtomicityNotSupported 5760 the batch requires atomic execution and the wallet cannot do it

Codes 4001 to 4901 come from EIP-1193, and codes 5700 to 5760 from EIP-5792.