Skip to content

Wallet.getCapabilities

Returns what the wallet can do for an account, by chain: whether it runs batches atomically, sponsors gas, and so on (EIP-5792).

import { Effect } from "effect";
import { Address, 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 ADDRESS = Address.makeUnsafe("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266");
const program = Wallet.getCapabilities(ADDRESS);
const capabilities = await program.pipe(
Effect.provide(Transport.eip1193(provider)),
Effect.runPromise,
);

A wallet method runs over Transport.eip1193. The examples below leave the transport out.

Pass chain ids to ask about those chains only.

import { Effect } from "effect";
import { Address } from "@ethect/core";
import { Wallet } from "@ethect/core/rpc";
const ADDRESS = Address.makeUnsafe("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266");
const onBase = Effect.gen(function* () {
const capabilities = yield* Wallet.getCapabilities(ADDRESS, [8453, 84532]);
return capabilities[8453];
});

The atomic capability of EIP-5792 says whether the wallet runs a batch atomically on a chain. Read it before you set atomicRequired in Wallet.sendCalls.

import { Effect } from "effect";
import { Address } from "@ethect/core";
import { Wallet } from "@ethect/core/rpc";
const ADDRESS = Address.makeUnsafe("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266");
const atomic = Effect.gen(function* () {
const capabilities = yield* Wallet.getCapabilities(ADDRESS, [8453]);
return capabilities[8453]?.atomic?.status === "supported";
});

By the EIP, status is "supported", "ready" (the wallet can upgrade, pending the user’s approval) or "unsupported".

Capabilities listed under chain 0 hold on every chain the wallet supports.

import { Effect } from "effect";
import { Address } from "@ethect/core";
import { Wallet } from "@ethect/core/rpc";
const ADDRESS = Address.makeUnsafe("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266");
const everywhere = Effect.gen(function* () {
const capabilities = yield* Wallet.getCapabilities(ADDRESS);
return Object.keys(capabilities[0] ?? {});
});

Effect<WalletCapabilities.ByChain, Method.Error, Transport>

A record from chain id to the capabilities of that chain, by name. See WalletCapabilities.

The example answer of the EIP, as the wallet sends it:

{
"0x0": { "flow-control": { "supported": true } },
"0x2105": {
"paymasterService": { "supported": true },
"sessionKeys": { "supported": true }
},
"0x14A34": { "auxiliaryFunds": { "supported": true } }
}

It decodes to an object with the keys 0, 8453 and 84532.

The account to ask about. A plain string is not accepted: build it with Address.makeUnsafe, or with Address.make when it comes from outside.

import { Address } from "@ethect/core";
import { Wallet } from "@ethect/core/rpc";
const ADDRESS = Address.makeUnsafe("0x70997970C51812dc3A010C7d01b50e0d17dc79C8");
const capabilities = Wallet.getCapabilities(ADDRESS);
  • Type: ReadonlyArray<number>

The chains to ask about. Left out, the param is not sent and the wallet answers for all the chains it supports.

import { Address } from "@ethect/core";
import { Wallet } from "@ethect/core/rpc";
const ADDRESS = Address.makeUnsafe("0x70997970C51812dc3A010C7d01b50e0d17dc79C8");
const capabilities = Wallet.getCapabilities(ADDRESS, [1, 10]);
  • Chain ids are numbers. The key "0x2105" decodes to 8453, and [8453, 84532] is sent as ["0x2105", "0x14a34"].
  • A missing chain is undefined. By the EIP, a wallet leaves out a chain it does not support instead of failing. capabilities[8453] is then undefined, whatever its type says.
  • Capabilities are open. Only the envelope is typed. A capability is a record of unknown values, because each one is defined by an ERC of its own.
  • Chain 0 means every chain. A capability the wallet has everywhere is listed once, under 0.
  • Every key must be a chain id. A key of the answer that is not a hex quantity, such as "8453", fails the call with a CodecError on the result: no chain is left out unseen.

The three errors every method can fail with. The cases specific to this method, from EIP-5792 and against anvil 1.9:

Error Reason When
RpcError Unauthorized the user has not connected the address to the app (code 4100)
RpcError MethodNotFound the call goes to a node: anvil does not serve the method
CodecError on: "params" a chain id is negative or not an integer: nothing is sent

wallet_getCapabilities