# youchain-providers

> YOUChain module to handle requests to external providers.

Latest version **1.0.4-alpha.3** (published 2020-12-19) · LGPL-3.0 license · 0 weekly downloads

## Install

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

## Health

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

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

Warnings: low downloads.

Negative: insecure dependencies; abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4-alpha.3 |
| Published | 2020-12-19 |
| First published | 2019-03-12 |
| Weekly downloads | 0 |
| License | LGPL-3.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 8 |
| Unpacked size | 98.6 KB |
| Known vulnerabilities | 0 (+7 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 3 |
| Maintainers | youchain |

## Links

- npm: https://www.npmjs.com/package/youchain-providers
- Repository: https://github.com/youchainhq/youchain.js/tree/1.0/packages/youchain-providers
- npm.io page: https://npm.io/package/youchain-providers

## Dependencies (8)

- [oboe](https://npm.io/package/oboe.md) 2.1.4
- [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) git://github.com/frozeman/WebSocket-Node.git#browserifyCompatible
- [@types/node](https://npm.io/package/@types/node.md) ^10.12.18
- [xhr2-cookies](https://npm.io/package/xhr2-cookies.md) 1.1.0
- [eventemitter3](https://npm.io/package/eventemitter3.md) 3.1.0
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.3.1

## Recent versions

- 1.0.4-alpha.3 (latest) — 2020-12-19
- 1.0.4-alpha.2 — 2020-12-19
- 1.0.4-alpha.1 — 2020-12-19
- 1.0.4-alpha.0 — 2020-12-18
- 1.0.3 — 2020-09-09
- 1.0.2 — 2020-09-03
- 1.0.1 — 2020-05-06
- 1.0.1-alpha.1 — 2020-04-22
- 1.0.1-alpha.0 — 2020-04-21
- 1.0.0 — 2020-04-11
- 1.0.0-alpha.84 — 2020-03-28
- 1.0.0-alpha.83 — 2020-03-25
- 1.0.0-alpha.82 — 2020-03-25
- 1.0.0-alpha.81 — 2020-03-25
- 1.0.0-alpha.80 — 2020-03-25
- … 59 more at https://npm.io/package/youchain-providers/versions

## README

# youchain-providers

This is a sub package of [youchain.js][repo]

## Installation

```bash
npm install youchain-providers
```

## Usage Examples

#### HttpProvider

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

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

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

const httpProvider = new HttpProvider('http://localhost:8283', 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 'youchain-providers';
const options = {
    timeout: 30000,
    headers: {
        authorization: 'Basic username:password'
    }
};

const websocketProvider = new WebsocketProvider('ws://localhost:8283', options);
```

#### IpcProvider

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

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

#### BatchRequest

The BatchRequest provides the possibility to send JSON-RPC requests as batch.

```js
import {ProvidersModuleFactory, BatchRequest} 'youchain-providers';

const provider = new ProvidersModuleFactory()
                        .createProviderResolver
                        .resolve('http://localhost:8283');

const batchRequest = new BatchRequest(provider);

batchRequest.add(youchain.you.getBalance.request(
    '0x0000000000000000000000000000000000000000',
    'latest',
    callback
));

await batchRequest.execute();
```

#### ProviderDetector

Checks if an provider is given from the environment and returns the provider.

```js
import {ProvidersModuleFactory} from 'youchain-providers';

const providerDetector = new ProvidersModuleFactory.createProviderDetector();
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 youchain has internally just one provider interface and we have no direct dependency to third party providers.

```js
import {ProvidersModuleFactory} 'youchain-providers';

const socketProviderAdapter = new ProvidersModuleFactory()
                        .createProviderResolver
                        .resolve('ws://localhost:8283');
```

## Types

All the typescript typings are placed in the types folder.

[repo]: https://github.com/youchainhq/youchain.js

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