eth-provider (original) (raw)

0.13.7 • Public • Published 10 months ago

eth-provider

A Universal Ethereum Provider Client

Seamlessly connect to HTTP, WebSocket, IPC and Injected RPC transports in Node and the Browser!

Goals

Install

npm install eth-provider --save

Use

const provider = require('eth-provider') const web3 = new Web3(provider())

const provider = require('eth-provider') const web3 = new Web3(provider('wss://sepolia.infura.io/ws/v3/${INFURA_ID}))

const provider = require('eth-provider') const web3 = new Web3(provider(['injected', 'wss://sepolia.infura.io/ws/v3/${INFURA_ID}']))

const provider = require('eth-provider') const web3 = new Web3(provider('direct'))

Presets

View all possible presets here

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

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.