# eth-provider

> A Universal Ethereum Provider

Latest version **0.13.7** (published 2024-08-15) · GPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install eth-provider
pnpm add eth-provider
yarn add eth-provider
bun add eth-provider
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.13.7 |
| Published | 2024-08-15 |
| First published | 2018-05-31 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 548 KB |
| Known vulnerabilities | 0 (+4 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 191 |
| Author | Jordan Muir |
| Maintainers | cjm |

## Links

- npm: https://www.npmjs.com/package/eth-provider
- Repository: https://github.com/floating/eth-provider
- Homepage: https://github.com/floating/eth-provider#readme
- Issues: https://github.com/floating/eth-provider/issues
- npm.io page: https://npm.io/package/eth-provider

## Dependencies (6)

- [ws](https://npm.io/package/ws.md) 8.9.0
- [oboe](https://npm.io/package/oboe.md) 2.1.5
- [uuid](https://npm.io/package/uuid.md) 9.0.0
- [events](https://npm.io/package/events.md) 3.3.0
- [xhr2-cookies](https://npm.io/package/xhr2-cookies.md) 1.1.0
- [ethereum-provider](https://npm.io/package/ethereum-provider.md) 0.7.7

## Recent versions

- 0.13.7 (latest) — 2024-08-15
- 0.13.6 — 2022-10-27
- 0.13.5 — 2022-10-11
- 0.13.4 — 2022-09-29
- 0.13.3 — 2022-09-23
- 0.13.2 — 2022-09-19
- 0.13.1 — 2022-09-14
- 0.12.1 — 2022-06-09
- 0.12.0 — 2022-06-07
- 0.11.2 — 2022-05-25
- 0.11.0 — 2022-04-22
- 0.10.0 — 2021-12-23
- 0.9.8 — 2021-11-24
- 0.9.7 — 2021-10-19
- 0.9.6 — 2021-10-16
- … 33 more at https://npm.io/package/eth-provider/versions

## README

<br>
<div align="center">
  <img src="/asset/header.png?raw=true" alt="eth-provider" height="400"/>
</div>
<br>
<br>
<h3 align="center">A Universal Ethereum Provider Client</h3>
<p align="center">Seamlessly connect to  <b>HTTP</b>, <b>WebSocket</b>, <b>IPC</b> and <b>Injected</b> RPC transports in <b>Node</b> and the <b>Browser</b>!</p>
<br>
<br>

### Goals
* Follows [EIP 1193](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1193.md) Spec
* Support all transport types (websocket, http, ipc & injected)
* Attempt connection to an array of RPC endpoints until successful connection
* Reconnect when connection is lost
* Emit helpful status updates so apps can handle changes gracefully

### Install
```
npm install eth-provider --save
```

### Use

```js
const provider = require('eth-provider')
const web3 = new Web3(provider())
```
* By default, eth-provider will first try to discover providers injected by the environment, usually by a browser or extension
* If eth-provider fails to find an injected provider it will attempt to connect to local providers running on the user's device like [Frame](https://github.com/floating/frame), Geth or Parity
* You can override these defaults by passing in your own RPC targets
```js
const provider = require('eth-provider')
const web3 = new Web3(provider('wss://sepolia.infura.io/ws/v3/${INFURA_ID}))
```
* When passing in multiple RPC targets order them by priority
* When eth-provider fails to connect to a target it will automatically attempt to connect to the next priority target
* For example `['injected', 'wss://sepolia.infura.io/ws/v3/${INFURA_ID}']` will first try to discover injected providers and if unsuccessful connect to the Infura endpoint
```js
const provider = require('eth-provider')
const web3 = new Web3(provider(['injected', 'wss://sepolia.infura.io/ws/v3/${INFURA_ID}']))
```
* In Node and Electron you'll have access to IPC endpoints created by Geth or Parity that cannot be accessed by the Browser. You can connect to these by using the `'direct'` preset, or by passing custom IPC paths
```js
const provider = require('eth-provider')
const web3 = new Web3(provider('direct'))
```

### Presets
* **`injected`** - Discover providers injected by environment, usually by the browser or a browser extension
  * Browser
    * `['injected']`
* **`frame`** - Connect to [Frame](https://github.com/floating/frame) running on the user's device
  * Browser/Node/Electron
    * `['ws://127.0.0.1:1248', 'http://127.0.0.1:1248']`
* **`direct`** - Connect to local Ethereum nodes running on the user's device
  * Browser
    * `['ws://127.0.0.1:8546', 'http://127.0.0.1:8545']`
  * Node/Electron
    * `[/* Default IPC paths for platform */, 'ws://127.0.0.1:8546', 'http://127.0.0.1:8545']`
* **`infura`** - Connect to Mainnet Infura
  * Browser/Node/Electron
    * `['wss://mainnet.infura.io/ws/v3/${infuraId}', 'https://mainnet.infura.io/v3/${infuraId}']`
* **`alchemy`** - Connect to Mainnet Alchemy
  * Browser/Node/Electron
    * `['wss://eth-mainnet.ws.alchemyapi.io/v2/${alchemyId}', 'https://eth-mainnet.alchemyapi.io/v2/${alchemyId}']`

View all possible presets [here](https://github.com/floating/eth-provider/blob/master/presets/index.js)

If you do not pass any targets, eth-provider will use default targets `['injected', 'frame']` in the Browser and `['frame', 'direct']` in Node and Electron.

### Options

When creating the provider you can also pass an options object

* `infuraId` - Your projects Infura ID
* `alchemyId` - Your projects Alchemy ID
* `origin` - Used when connecting from outside of a browser env to declare the identity of your connection to interfaces like Frame (this currently doesn't work with HTTP connections)

`provider('infura', { infuraId: '123abc' })` or `provider({ origin: 'DappName', infuraId: '123abc' })`

The origin setting will only be applied when a dapp is connecting to from outside of a browser env.

---
_Source: https://npm.io/package/eth-provider · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
