# susyweb-providers

> SusyWeb module to handle requests to external providers.

Latest version **1.0.0-beta.55** (published 2019-06-20) · LGPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install susyweb-providers
pnpm add susyweb-providers
yarn add susyweb-providers
bun add susyweb-providers
```

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-beta.55 |
| Published | 2019-06-20 |
| First published | 2019-06-20 |
| Weekly downloads | 0 |
| License | LGPL-3.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 11 |
| Unpacked size | 138.3 KB |
| Known vulnerabilities | 0 (+7 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | superstring |

## Links

- npm: https://www.npmjs.com/package/susyweb-providers
- Repository: https://octonion.institute/susy-js/susyweb.js/tree/1.0/packages/susyweb-providers
- npm.io page: https://npm.io/package/susyweb-providers

## Dependencies (11)

- [lodash](https://npm.io/package/lodash.md) ^4.17.11
- [url-parse](https://npm.io/package/url-parse.md) 1.4.4
- [websocket](https://npm.io/package/websocket.md) ^1.0.28
- [@types/node](https://npm.io/package/@types/node.md) ^10.12.18
- [susyweb-core](https://npm.io/package/susyweb-core.md) 1.0.0-beta.55
- [xhr2-cookies](https://npm.io/package/xhr2-cookies.md) 1.1.0
- [eventemitter3](https://npm.io/package/eventemitter3.md) 3.1.0
- [susyweb-utils](https://npm.io/package/susyweb-utils.md) 1.0.0-beta.55
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.3.1
- [susyweb-core-method](https://npm.io/package/susyweb-core-method.md) 1.0.0-beta.55
- [susyweb-core-helpers](https://npm.io/package/susyweb-core-helpers.md) 1.0.0-beta.55

## Recent versions

- 1.0.0-beta.55 (latest) — 2019-06-20
- 1.0.0-beta.52 — 2019-06-20

## README

# susyweb-providers

This is a sub module of [susyweb.js][repo]

## Installation

```bash
npm install susyweb-providers
```

## Usage Examples

#### HttpProvider
You can pass with the options object the timeout and all known HTTP headers. 

```js 
import {HttpProvider} from 'susyweb-providers';

const options = {
    timeout: 20000,
    headers: [
        {
            name: 'Access-Control-Allow-Origin', value: '*'
        },
        ...
    ]
};

const httpProvider = new HttpProvider('http://localhost:8545', options); 
```

#### WebsocketProvider

Instead of setting a authorization header you could also define the credentials over the URL with:
```ws://username:password@localhost:8546```

```js 
import {WebsocketProvider} from 'susyweb-providers';
const options = { 
    timeout: 30000, 
    headers: {
        authorization: 'Basic username:password'
    }
};
 
const websocketProvider = new WebsocketProvider('ws://localhost:8546', options);
```

#### IpcProvider
```js 
import {IpcProvider} from 'susyweb-providers';
import net from 'net';

const ipcProvider = new IpcProvider('/Users/me/Library/Sophon/graviton.ipc', net);
```

#### BatchRequest
The BatchRequest provides the possibility to send JSON-RPC requests as batch.
Please read the [documentation][docs] for more.

```js 
import {ProviderResolver, BatchRequest} 'susyweb-providers';

const provider = new ProviderResolver().resolve('ws://localhost:8546');
const batchRequest = new BatchRequest(provider);

batchRequest.add(susyweb.sof.getBalance.request(
    '0x0000000000000000000000000000000000000000',
    'latest',
    callback
));

await batchRequest.execute();
```

#### ProviderDetector
Checks if an provider is given from the environment (Mist, SusyLink) and returns the provider.

```js
import {ProviderDetector} from 'susyweb-providers';

const givenProvider = ProviderDetector.detect();
```

#### ProviderResolver
The ProviderResolver resolves an url or an given provider object to the correct provider class. 
Because of the resolves does susyweb has internally just one provider interface and we have no direct dependency to third party providers.

```js 
import {ProviderResolver} 'susyweb-providers';

const socketProviderAdapter = new ProviderResolver().resolve('ws://localhost:8546');
```

## Types 

All the typescript typings are placed in the types folder. 

[docs]: http://susywebjs.readthedocs.io/en/1.0/
[repo]: https://octonion.institute/susy-js/susyweb.js

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