eth-provider
Advanced tools
Comparing version 0.2.5 to 0.4.0
@@ -21,2 +21,15 @@ const resolve = require('./resolve') | ||
module.exports = (targets = ['injected', 'frame'], options = {}) => provider(connections, resolve(targets, presets), options) | ||
module.exports = (targets, options) => { | ||
if (targets && !Array.isArray(targets) && typeof targets === 'object' && !options) { | ||
options = targets | ||
targets = undefined | ||
} | ||
if (!targets) targets = ['injected', 'frame'] | ||
if (!options) options = {} | ||
if (targets.indexOf('infura') > -1 && !options.infuraId) throw new Error('Infura was included as a connection target but no Infura project ID was passed in options e.g. { infuraId: \'123abc\' }') | ||
const sets = presets(options) | ||
return provider(connections, resolve(targets, sets), options) | ||
} |
@@ -9,2 +9,3 @@ const EventEmitter = require('events') | ||
this.targets = targets | ||
this.options = options | ||
this.connections = connections | ||
@@ -28,3 +29,3 @@ this.connected = false | ||
const { protocol, location } = this.targets[index] | ||
this.connection = this.connections[protocol](location) | ||
this.connection = this.connections[protocol](location, this.options) | ||
@@ -31,0 +32,0 @@ this.connection.on('error', err => { |
const EventEmitter = require('events') | ||
const uuid = require('uuid/v4') | ||
const { v4: uuid } = require('uuid') | ||
@@ -12,2 +12,3 @@ const dev = process.env.NODE_ENV === 'development' | ||
XHR = _XHR | ||
this.options = options | ||
this.connected = false | ||
@@ -104,2 +105,4 @@ this.subscriptions = false | ||
xhr.setRequestHeader('Content-Type', 'application/json') | ||
// Below not working becasue XHR lib blocks it claiming "restricted header" | ||
// if (this.options.origin) xhr.setRequestHeader('Origin', this.options.origin) | ||
xhr.timeout = 60 * 1000 | ||
@@ -106,0 +109,0 @@ xhr.onerror = res |
@@ -16,3 +16,3 @@ const EventEmitter = require('events') | ||
if (!WebSocket) this.emit('error', new Error('No WebSocket transport available')) | ||
try { this.socket = new WebSocket(url) } catch (e) { return this.emit('error', e) } | ||
try { this.socket = new WebSocket(url, [], { origin: options.origin }) } catch (e) { return this.emit('error', e) } | ||
this.socket.addEventListener('error', err => this.emit('error', err)) | ||
@@ -19,0 +19,0 @@ this.socket.addEventListener('open', () => { |
20
node.js
@@ -17,5 +17,4 @@ const resolve = require('./resolve') | ||
} else if (process.platform === 'win32') { | ||
ipc = [`\\\\.\\pipe\\geth.ipc`] | ||
ipc = ['\\\\.\\pipe\\geth.ipc'] | ||
} | ||
presets.direct = ipc.concat(presets.direct) | ||
@@ -29,2 +28,17 @@ const connections = { | ||
module.exports = (targets = ['injected', 'frame'], options = {}) => provider(connections, resolve(targets, presets), options) | ||
module.exports = (targets, options) => { | ||
if (typeof targets === 'string') targets = [targets] | ||
if (targets && !Array.isArray(targets) && typeof targets === 'object' && !options) { | ||
options = targets | ||
targets = undefined | ||
} | ||
if (!targets) targets = ['injected', 'frame'] | ||
if (!options) options = {} | ||
if (targets.indexOf('infura') > -1 && !options.infuraId) throw new Error('Infura was included as a connection target but no Infura project ID was passed in options e.g. { infuraId: \'123abc\' }') | ||
const sets = presets(options) | ||
sets.direct = ipc.concat(sets.direct) | ||
return provider(connections, resolve(targets, sets), options) | ||
} |
{ | ||
"name": "eth-provider", | ||
"version": "0.2.5", | ||
"version": "0.4.0", | ||
"description": "A Universal Ethereum Provider", | ||
@@ -8,9 +8,12 @@ "browser": "browser.js", | ||
"scripts": { | ||
"test": "standard && npm run test:web3:v0 && npm run test:web3:v1", | ||
"test": "standard && npm run test:web3:v0 && npm run test:web3:v1 && npm run test:frame && npm run test:endpoints && npm run test:eip1193", | ||
"test:web3": "npm run test:web3:v0 && npm run test:web3:latest", | ||
"test:web3:v0": "npm install web3@0.20.7 && mocha test/web3-v0.x.js", | ||
"test:web3:v1": "npm install web3@1.2.0 && mocha test/web3-v1.x.js", | ||
"test:web3:v1": "npm install web3@1.2.8 && mocha test/web3-v1.x.js", | ||
"test:web3:latest": "npm install web3@latest && mocha test/web3-v1.x.js", | ||
"test:frame": "standard && npm install web3@1.2.0 && mocha test/frame.js", | ||
"test:ipc": "standard && mocha test/ipc.js", | ||
"test:all": "standard && mocha", | ||
"test:frame": "npm install web3@1.2.8 && mocha test/frame.js", | ||
"test:endpoints": "npm install web3@1.2.8 && mocha test/endpoints.js", | ||
"test:eip1193": "mocha test/eip1193.js", | ||
"test:ipc": "mocha test/ipc.js", | ||
"test:all": "mocha", | ||
"prepublishOnly": "npm run test" | ||
@@ -21,3 +24,3 @@ }, | ||
"email": "jordan@frame.sh", | ||
"url": "https//frame.sh" | ||
"url": "https://frame.sh" | ||
}, | ||
@@ -27,13 +30,13 @@ "license": "GPL-3.0", | ||
"dependencies": { | ||
"ethereum-provider": "0.0.6", | ||
"oboe": "2.1.4", | ||
"uuid": "3.3.2", | ||
"ws": "7.1.2", | ||
"ethereum-provider": "0.1.1", | ||
"oboe": "2.1.5", | ||
"uuid": "8.1.0", | ||
"ws": "7.3.0", | ||
"xhr2-cookies": "1.1.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "6.2.0", | ||
"standard": "13.1.0", | ||
"web3": "^1.2.0" | ||
"mocha": "7.2.0", | ||
"standard": "14.3.4", | ||
"web3": "^1.2.8" | ||
} | ||
} |
@@ -1,9 +0,11 @@ | ||
module.exports = { | ||
injected: ['injected'], | ||
frame: ['ws://127.0.0.1:1248', 'http://127.0.0.1:1248'], | ||
direct: ['ws://127.0.0.1:8546', 'http://127.0.0.1:8545'], // IPC paths will be prepended in Node/Electron | ||
infura: ['wss://mainnet.infura.io/ws/v3/786ade30f36244469480aa5c2bf0743b', 'https://mainnet.infura.io/v3/786ade30f36244469480aa5c2bf0743b'], | ||
infuraRopsten: ['wss://ropsten.infura.io/ws/v3/786ade30f36244469480aa5c2bf0743b', 'https://ropsten.infura.io/v3/786ade30f36244469480aa5c2bf0743b'], | ||
infuraRinkeby: ['wss://rinkeby.infura.io/ws/v3/786ade30f36244469480aa5c2bf0743b', 'https://rinkeby.infura.io/v3/786ade30f36244469480aa5c2bf0743b'], | ||
infuraKovan: ['wss://kovan.infura.io/ws/v3/786ade30f36244469480aa5c2bf0743b', 'https://kovan.infura.io/v3/786ade30f36244469480aa5c2bf0743b'] | ||
module.exports = (options = {}) => { | ||
return { | ||
injected: ['injected'], | ||
frame: ['ws://127.0.0.1:1248', 'http://127.0.0.1:1248'], | ||
direct: ['ws://127.0.0.1:8546', 'http://127.0.0.1:8545'], // IPC paths will be prepended in Node/Electron | ||
infura: [`wss://mainnet.infura.io/ws/v3/${options.infuraId}`, `https://mainnet.infura.io/v3/${options.infuraId}`], | ||
infuraRopsten: [`wss://ropsten.infura.io/ws/v3/${options.infuraId}`, `https://ropsten.infura.io/v3/${options.infuraId}`], | ||
infuraRinkeby: [`wss://rinkeby.infura.io/ws/v3/${options.infuraId}`, `https://rinkeby.infura.io/v3/${options.infuraId}`], | ||
infuraKovan: [`wss://kovan.infura.io/ws/v3/${options.infuraId}`, `https://kovan.infura.io/v3/${options.infuraId}`] | ||
} | ||
} |
@@ -12,12 +12,8 @@ <br> | ||
### Notice | ||
* Evolving with [EIP 1193](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1193.md) | ||
* Testing and feedback is very much appreciated! | ||
### Goals | ||
* Support all transport types | ||
* Attempt connection to an array of RPC endpoints until success | ||
* 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 | ||
* Implement `eth_pollSubscriptions` method for HTTP subscriptions (supported by [Frame](https://github.com/floating/frame)) | ||
@@ -30,2 +26,3 @@ ### Install | ||
### Use | ||
```js | ||
@@ -40,10 +37,10 @@ const provider = require('eth-provider') | ||
const provider = require('eth-provider') | ||
const web3 = new Web3(provider('wss://rinkeby.infura.io/ws/v3/786ade30f36244469480aa5c2bf0743b')) | ||
const web3 = new Web3(provider('wss://rinkeby.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://rinkeby.infura.io/ws/v3/786ade30f36244469480aa5c2bf0743b']` will first try to discover injected providers and if unsuccessful connect to the Infura endpoint | ||
* For example `['injected', 'wss://rinkeby.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://rinkeby.infura.io/ws/v3/786ade30f36244469480aa5c2bf0743b'])) | ||
const web3 = new Web3(provider(['injected', 'wss://rinkeby.infura.io/ws/v3/${INFURA_ID}'])) | ||
``` | ||
@@ -70,13 +67,24 @@ * 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 | ||
* Browser/Node/Electron | ||
* `['wss://mainnet.infura.io/ws/v3/786ade30f36244469480aa5c2bf0743b', 'https://mainnet.infura.io/v3/786ade30f36244469480aa5c2bf0743b']` | ||
* `['wss://mainnet.infura.io/ws/v3/${INFURA_ID}', 'https://mainnet.infura.io/v3/${INFURA_ID}']` | ||
* **`infuraRinkeby`** - Connect to Rinkeby Infura | ||
* Browser/Node/Electron | ||
* `['wss://rinkeby.infura.io/ws/v3/786ade30f36244469480aa5c2bf0743b', 'https://rinkeby.infura.io/v3/786ade30f36244469480aa5c2bf0743b']` | ||
* `['wss://rinkeby.infura.io/ws/v3/${INFURA_ID}', 'https://rinkeby.infura.io/v3/${INFURA_ID}']` | ||
* **`infuraRopsten`** - Connect to Ropsten Infura | ||
* Browser/Node/Electron | ||
* `['wss://ropsten.infura.io/ws/v3/786ade30f36244469480aa5c2bf0743b', 'https://ropsten.infura.io/v3/786ade30f36244469480aa5c2bf0743b']` | ||
* `['wss://ropsten.infura.io/ws/v3/${INFURA_ID}', 'https://ropsten.infura.io/v3/${INFURA_ID}']` | ||
* **`infuraKovan`** - Connect to Kovan Infura | ||
* Browser/Node/Electron | ||
* `['wss://kovan.infura.io/ws/v3/786ade30f36244469480aa5c2bf0743b', 'https://kovan.infura.io/v3/786ade30f36244469480aa5c2bf0743b']` | ||
* `['wss://kovan.infura.io/ws/v3/${INFURA_ID}', 'https://kovan.infura.io/v3/${INFURA_ID}']` | ||
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 | ||
* `origin` - Used when connecting from outside of a browser env to declare you're origin (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. |
@@ -14,3 +14,3 @@ /* globals describe it */ | ||
describe('HTTP Provider (Frame)', () => { | ||
const httpProvider = provider('http://127.0.0.1:1248') | ||
const httpProvider = provider('http://127.0.0.1:1248', { origin: 'HTTPProviderOriginTest' }) // Origin settings currently don't work for HTTP connections | ||
const web3http = new Web3(httpProvider) | ||
@@ -17,0 +17,0 @@ describe('Subscribe via HTTP (please wait for next block)', () => { |
@@ -78,3 +78,3 @@ /* globals describe it */ | ||
describe('Mainnet', () => { | ||
const p = provider('infura') | ||
const p = provider('infura', { infuraId: '786ade30f36244469480aa5c2bf0743b' }) | ||
const web3 = new Web3(p) | ||
@@ -91,3 +91,3 @@ it('net_version', done => { | ||
describe('Ropsten', () => { | ||
const p = provider('infuraRopsten') | ||
const p = provider('infuraRopsten', { infuraId: '786ade30f36244469480aa5c2bf0743b' }) | ||
const web3 = new Web3(p) | ||
@@ -104,3 +104,3 @@ it('net_version', done => { | ||
describe('Rinkeby', () => { | ||
const p = provider('infuraRinkeby') | ||
const p = provider('infuraRinkeby', { infuraId: '786ade30f36244469480aa5c2bf0743b' }) | ||
const web3 = new Web3(p) | ||
@@ -117,3 +117,3 @@ it('net_version', done => { | ||
describe('Kovan', () => { | ||
const p = provider('infuraKovan') | ||
const p = provider('infuraKovan', { infuraId: '786ade30f36244469480aa5c2bf0743b' }) | ||
const web3 = new Web3(p) | ||
@@ -120,0 +120,0 @@ it('net_version', done => { |
@@ -79,3 +79,3 @@ /* globals describe it */ | ||
describe('Mainnet', () => { | ||
const p = provider('infura') | ||
const p = provider('infura', { infuraId: '786ade30f36244469480aa5c2bf0743b' }) | ||
const web3 = new Web3(p) | ||
@@ -92,3 +92,3 @@ it('net_version', done => { | ||
describe('Ropsten', () => { | ||
const p = provider('infuraRopsten') | ||
const p = provider('infuraRopsten', { infuraId: '786ade30f36244469480aa5c2bf0743b' }) | ||
const web3 = new Web3(p) | ||
@@ -105,3 +105,3 @@ it('net_version', done => { | ||
describe('Rinkeby', () => { | ||
const p = provider('infuraRinkeby') | ||
const p = provider('infuraRinkeby', { infuraId: '786ade30f36244469480aa5c2bf0743b' }) | ||
const web3 = new Web3(p) | ||
@@ -118,3 +118,3 @@ it('net_version', done => { | ||
describe('Kovan', () => { | ||
const p = provider('infuraKovan') | ||
const p = provider('infuraKovan', { infuraId: '786ade30f36244469480aa5c2bf0743b' }) | ||
const web3 = new Web3(p) | ||
@@ -121,0 +121,0 @@ it('net_version', done => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
548361
23
914
87
+ Addedethereum-provider@0.1.1(transitive)
+ Addedoboe@2.1.5(transitive)
+ Addeduuid@8.1.0(transitive)
+ Addedws@7.3.0(transitive)
- Removedasync-limiter@1.0.1(transitive)
- Removedethereum-provider@0.0.6(transitive)
- Removedoboe@2.1.4(transitive)
- Removeduuid@3.3.2(transitive)
- Removedws@7.1.2(transitive)
Updatedethereum-provider@0.1.1
Updatedoboe@2.1.5
Updateduuid@8.1.0
Updatedws@7.3.0