# EIP-1193 Providers

## Overview

[EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) is a standard that defines a JavaScript Ethereum Provider API for interacting from an arbitrary JavaScript environment (e.g. Web Application, Server, etc) to the Ethereum network.

You would typically use an EIP-1193 Provider when communicating to a Wallet. For example, most Browser Extension Wallets inject a `window.ethereum` object into the webpage that conforms to the EIP-1193 API as a means to interact with Ethereum.

## Libraries

There are a number of libraries that distribute EIP-1193 Providers, such as:

| Library                                                                                                                 | Description                                             |
| ----------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------- |
| [`mipd`](https://github.com/wevm/mipd)                                                                                  | Multi-injected browser wallet provider discovery        |
| [`@walletconnect/ethereum-provider`](https://www.npmjs.com/package/@walletconnect/ethereum-provider)                   | Connect and interact with WalletConnect-enabled wallets |
| [`@metamask/sdk`](https://docs.metamask.io/wallet/connect/metamask-sdk/javascript/)                                     | Connect and interact with MetaMask Wallet               |
| [`@coinbase/wallet-sdk`](https://github.com/coinbase/coinbase-wallet-sdk)                                               | Connect and interact with Coinbase Wallet               |
| [`@safe-global/safe-apps-provider`](https://github.com/safe-global/safe-apps-sdk/tree/main/packages/safe-apps-provider) | Connect and interact with Safe Wallets                  |

## Examples

### Instantiating with External Providers

External EIP-1193 Providers can be instantiated with [`Provider.from`](/api/Provider/from).

```ts twoslash
import 'ox/window'
import { Provider } from 'ox'
 
const provider = Provider.from(window.ethereum)
 
const blockNumber = await provider.request({ method: 'eth_blockNumber' })
```

:::note
**Note:** You can also plug in a Provider from any of the [Libraries](#libraries) listed above.
:::

### Instantiating with an RPC Transport

Ox's [`RpcTransport`](/api/RpcTransport) is also EIP-1193 compliant, and can be used to instantiate an EIP-1193 Provider. This means you can use any HTTP RPC endpoint as an EIP-1193 Provider.

```ts twoslash
import { Provider, RpcTransport } from 'ox'

const transport = RpcTransport.fromHttp('https://1.rpc.thirdweb.com')
const provider = Provider.from(transport)
```

### Instantiating a Provider with Events

Event emitters for EIP-1193 Providers can be created using [`Provider.createEmitter`](/api/Provider/createEmitter).

Useful for Wallets that distribute an EIP-1193 Provider (e.g. webpage injection via `window.ethereum`).

```ts twoslash
// @noErrors
import { Provider, RpcRequest, RpcResponse } from 'ox'

// 1. Instantiate a Provider Emitter.
const emitter = Provider.createEmitter() // [!code ++]

const store = RpcRequest.createStore()

const provider = Provider.from({
  // 2. Pass the Emitter to the Provider.
  ...emitter, // [!code ++]
  async request(args) {
    return await fetch('https://1.rpc.thirdweb.com', {
      body: JSON.stringify(store.prepare(args)),
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
      },
    })
      .then((res) => res.json())
      .then(RpcResponse.parse)
  },
})

// 3. Emit Provider Events.
emitter.emit('accountsChanged', ['0x...']) // [!code ++]
```

## Related Modules

| Module                    | Description                                                                                      |
| ------------------------- | ------------------------------------------------------------------------------------------------ |
| [Provider](/api/Provider) | Utilities & types for working with [EIP-1193 Providers](https://eips.ethereum.org/EIPS/eip-1193) |
