Skip to Content
butr
API reference

@usebutr/evm

EIP-6963 and injected discovery, the EIP-1193 adapter builder, and the EIP-1193 types.

Discovery

discoverEvmAdapters(onAdapter): () => void

Subscribes to EIP-6963 announcements and calls onAdapter(adapter) once per wallet, deduplicated by info.rdns. The listener stays attached, so wallets that boot late still register. It is a WalletSource as-is:

import type { WalletManagerConfig } from "@usebutr/core";
import { discoverEvmAdapters } from "@usebutr/evm";

const config: WalletManagerConfig = { sources: [discoverEvmAdapters] };

discoverInjectedAdapter(onAdapter): () => void

The last-resort path for wallets that expose only window.ethereum and never announce through EIP-6963. When subscribed, it emits one adapter with the id injected:legacy if window.ethereum is an EIP-1193 provider. On its own it also lists a wallet that announced through EIP-6963; autoDiscovery(["evm"]) from @usebutr/wallets lists it only when no EIP-6963 wallet announced.

Constants: ANNOUNCE_EVENT and REQUEST_EVENT (the EIP-6963 event names), GENERIC_INJECTED_ICON (the legacy adapter's icon).

Adapter builder

buildEvmAdapter(identity: EvmIdentity, provider: Eip1193Provider): EvmAdapter

Wraps any EIP-1193 provider. identity is { icon?, id, name }; EIP-6963 discovery passes the wallet's rdns as the id. The adapter always defines disconnect, subscribe, requestAccounts, switchChain, signMessage, sendTx, getBalance and getTransactionReceipt, and getSigner() resolves { kind: "eip1193", provider }. See the injected EVM connector for how each behaves.

createEip1193Core(identity: EvmIdentity, provider: Eip1193Provider): Eip1193Core

Every member of buildEvmAdapter except connect, disconnect and requestAccounts, for a transport that owns the session itself, as WalletConnect's EVM namespace does.

isEip1193Provider(value: unknown): value is Eip1193Provider

A structural check for a provider of unknown origin, such as window.ethereum. A butr signer narrows on kind === "eip1193" instead.

Helpers

  • chainIdHexToDecimal(hex: string): string
  • chainIdDecimalToHex(decimal: string): string
  • formatEther(wei: bigint): string: trims trailing zeros.

Byte helpers (bytesToHex, hexToBytes, …) and the EVM chain registry (EVM_CHAINS, CHAINS_BY_PLATFORM.evm) live in @usebutr/core.

Signer

Importing the package registers the eip1193 signer kind. WalletSignerOf<"eip1193"> from @usebutr/core is { kind: "eip1193"; provider: Eip1193Provider }. The WalletConnect EVM namespace resolves the same kind.

Types

Eip1193Provider (request, on, removeListener), Eip1193RequestArgs, Eip1193Listener, Eip1193Value, Eip1193Object, Eip6963ProviderInfo, Eip6963ProviderDetail, Eip6963AnnounceEvent.

Eip1193Provider.request returns Promise<Eip1193Value | undefined>: loose on purpose, so the package takes no dependency on viem. viem's custom() transport accepts it directly.

Source: packages/evm/src/index.ts.