EIP-1193 Compliance
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
EIP-1193 Compliance in the Walletless project refers to the implementation of a "man-in-the-middle" virtual Ethereum provider that adheres to the Ethereum Provider JavaScript API standard. This allows DApps to interact with the provider using standard methods while the library redirects read operations to an RPC node (like Anvil) and handles write operations through local signing.
Sources: README.md:9-14, src/types.ts:98-103
The architecture ensures that high-performance E2E testing can be achieved by removing browser extension overhead and providing deterministic control over wallet interactions, such as signature rejections or account switching, all through an interface compatible with common libraries like Wagmi and Viem.
Sources: README.md:21-27, package.json:2-15
Core Architecture and Data Flow
The provider implements the EIP-1193 request method as the primary entry point for all JSON-RPC interactions. It categorizes incoming requests into three logical flows: Read, Write, and Wallet methods.
Request Routing Logic
The routing is determined by identifying the nature of the RPC method:
- Read Methods: Routed directly to the configured Anvil RPC URL via standard
fetchPOST requests. - Write/Signing Methods: Handled locally using an internal
walletClientand a private key orAccountobject. - Wallet Methods: Managed by the provider's internal state machine to track current accounts, chain IDs, and connection status.
This diagram illustrates how the EIP-1193 request is intercepted and routed based on the method type.
Implementation Details
The E2EProvider Interface
The project defines the E2EProvider type to match EIP-1193 requirements, including the request function and event emitter capabilities (on, removeListener, emit).
Sources: src/types.ts:91-104
| Component | Description | Source |
|---|---|---|
request | The main EIP-1193 function for sending JSON-RPC requests. | src/types.ts:91-95 |
InternalState | Tracks the active account, walletClient, currentChain, and RPC endpoints. | src/provider.ts:80-89 |
walletClient | A Viem-based client used to sign transactions and messages locally. | src/provider.ts:145-149 |
Event Handling
Compliance requires the emission of specific events to notify the DApp of state changes. The provider implements:
accountsChanged: Triggered whensetSigningAccountis called.chainChanged: Triggered onwallet_switchEthereumChainorsetChain.connect: Triggered upon the first successfuleth_requestAccountscall.disconnect: Triggered when the provider is manually disconnected.
Sources: src/types.ts:74-82, src/provider.ts:200-207
Method Categorization
The system maintains strict lists of methods to determine how to process each request.
Method Types Summary
| Category | Example Methods | Handling Logic |
|---|---|---|
| Read | eth_call, eth_getBalance, eth_blockNumber | Forwarded to rpcUrl. |
| Write | eth_sendTransaction, personal_sign, eth_signTypedData_v4 | Signed by local account. |
| Wallet | eth_accounts, eth_chainId, wallet_switchEthereumChain | Returns internal state. |
Sources: src/constants.ts:89-150
Transaction and Signature Handling
When a write method like eth_sendTransaction is called, the provider uses its internal walletClient to sign the payload before sending it to the network. This process supports EIP-712 typed data and standard personal message signing.
Sequence showing the local signing flow for transactions and the interception point for simulated rejections.
Sources: src/provider.ts:258-293, test/provider.spec.ts:590-605
EIP-1193 Error Codes
The provider implements standard error codes to simulate realistic wallet behavior, particularly for testing failure modes in DApps.
| Error Name | Code | Meaning |
|---|---|---|
UserRejectedRequest | 4001 | The user rejected the transaction or signature. |
Unauthorized | 4100 | The provider is not authorized for the requested method. |
UnsupportedMethod | 4200 | The method is not supported by the provider. |
Disconnected | 4900 | The provider is disconnected from all chains. |
ChainDisconnected | 4901 | The provider is disconnected from the specific chain. |
Sources: src/types.ts:162-172
Integration with Wagmi (e2eConnector)
The e2eConnector acts as a bridge between the virtual EIP-1193 provider and the Wagmi library. It ensures that events emitted by the provider (like accountsChanged) are correctly forwarded to Wagmi's internal emitter to trigger UI updates.
The event bridge between the virtual provider and Wagmi state management.
Sources: src/connector.ts:114-129
Conclusion
EIP-1193 Compliance in Walletless enables a high-fidelity simulation of Ethereum wallets within automated testing environments. By adhering to the standard, it allows developers to swap real wallets for a virtualized, programmable instance that provides fine-grained control over blockchain interactions without requiring modifications to the DApp's core logic.
Sources: README.md:1-6, src/provider.ts:108-117