---
eip: 2700
label: EIP-2700
title: JavaScript Provider Event Emitter
status: Final
type: Standards Track
category: Interface
created: 2020-06-05
official: https://eips.ethereum.org/EIPS/eip-2700
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2700.md
canonical: https://eips.huatuo.xyz/eip-2700/
lang: en
tldr: Defines the minimal on/removeListener event-emitter shape that injected JavaScript Ethereum providers expose, so dApps can subscribe to wallet and chain events the same way everywhere.
tags: [wallet, provider, javascript, events, interface]
---

# EIP-2700: JavaScript Provider Event Emitter

> A standard mechanism for JavaScript Ethereum Providers to notify clients about chain state changes when both are able to interface with each other via a shared JavaScript object.

**TL;DR:** Defines the minimal on/removeListener event-emitter shape that injected JavaScript Ethereum providers expose, so dApps can subscribe to wallet and chain events the same way everywhere.

## What problem does it solve?

Browser wallets, desktop apps and Node.js plugins inject an Ethereum provider object into the JavaScript runtime so apps can talk to the chain. Apps also need to be *told* when things change: the user switches account, the chain changes, a subscription delivers new data.

Before this EIP there was no agreed shape for how an app registers for those notifications. ERC-2700 codifies the existing practice: the provider is a small event emitter with `on` and `removeListener`. It is a retrospective standard, written to match what wallets already did.

## How it works

The whole interface is two methods:

```ts
interface EthereumProvider {
  on(eventName: string, listener: (...params: unknown[]) => void): void;
  removeListener(eventName: string, listener: (...params: unknown[]) => void): void;
}
```

Rules:

- If `on` is called with an event name the provider knows, it **must** call the listener whenever that event occurs.
- Adding the same listener twice to the same event may result in one call or two calls per event; the provider chooses.
- `removeListener` with a previously added listener **must** reduce by one the number of times that listener is called per event.

What the spec deliberately leaves out:

- **Which events exist** and what their payloads look like. Those are defined elsewhere, most notably in [EIP-1193](/eip-1193/) (`connect`, `disconnect`, `chainChanged`, `accountsChanged`, `message`).
- **How the provider is discovered** (for example `window.ethereum`, or the multi-wallet announcement flow of [EIP-6963](/eip-6963/)).

## Sample code

Subscribing and cleaning up in a browser dApp:

```ts
type Listener = (...params: unknown[]) => void;
interface EthereumProvider {
  on(event: string, listener: Listener): void;
  removeListener(event: string, listener: Listener): void;
}

const provider = (window as any).ethereum as EthereumProvider | undefined;
if (!provider) throw new Error("No injected provider");

const onAccounts: Listener = (accounts) => {
  console.log("accounts changed:", accounts);
};
const onChain: Listener = (chainId) => {
  console.log("chain changed:", chainId); // hex string per EIP-1193
};

provider.on("accountsChanged", onAccounts);
provider.on("chainChanged", onChain);

// Later, e.g. when a React component unmounts:
export function cleanup() {
  provider!.removeListener("accountsChanged", onAccounts);
  provider!.removeListener("chainChanged", onChain);
}
```

A minimal provider-side implementation on top of Node's `EventEmitter` already satisfies the interface:

```ts
import { EventEmitter } from "node:events";
class MyProvider extends EventEmitter {} // inherits on() and removeListener()
```

## Things to know

- Status is **Final**, but the standard is intentionally tiny. In practice you will read it together with [EIP-1193](/eip-1193/), which defines the `request` method and the actual event names.
- Keep a reference to the exact listener function you pass to `on`; `removeListener` needs the same function object, so inline arrow functions cannot be removed later.
- Because duplicate registrations may or may not fire twice, avoid adding the same listener more than once.
- The spec assumes a trusted relationship: the app trusts whatever provider was injected into its runtime. Apps that support several wallets should discover them explicitly rather than trusting a single global object.


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-2700
