1.0.4-alpha.3 • Published 4 years ago

youchain-providers v1.0.4-alpha.3

Weekly downloads
81
License
LGPL-3.0
Repository
github
Last release
4 years ago

youchain-providers

This is a sub package of youchain.js

Installation

npm install youchain-providers

Usage Examples

HttpProvider

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

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

import {WebsocketProvider} from 'youchain-providers';
const options = {
    timeout: 30000,
    headers: {
        authorization: 'Basic username:password'
    }
};

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

IpcProvider

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.

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.

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.

import {ProvidersModuleFactory} 'youchain-providers';

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

Types

All the typescript typings are placed in the types folder.

1.0.4-alpha.3

4 years ago

1.0.4-alpha.1

4 years ago

1.0.4-alpha.0

4 years ago

1.0.4-alpha.2

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

5 years ago

1.0.1-alpha.1

5 years ago

1.0.1-alpha.0

5 years ago

1.0.0

5 years ago

1.0.0-alpha.84

5 years ago

1.0.0-alpha.83

5 years ago

1.0.0-alpha.82

5 years ago

1.0.0-alpha.81

5 years ago

1.0.0-alpha.78

5 years ago

1.0.0-alpha.79

5 years ago

1.0.0-alpha.80

5 years ago

1.0.0-alpha.76

5 years ago

1.0.0-alpha.77

5 years ago

1.0.0-alpha.74

5 years ago

1.0.0-alpha.73

5 years ago

1.0.0-alpha.75

5 years ago

1.0.0-alpha.72

5 years ago

1.0.0-alpha.71

5 years ago

1.0.0-alpha.65

5 years ago

1.0.0-alpha.64

5 years ago

1.0.0-alpha.63

5 years ago

1.0.0-alpha.62

5 years ago

1.0.0-alpha.61

5 years ago

1.0.0-alpha.60

5 years ago

1.0.0-alpha.59

5 years ago

1.0.0-alpha.58

5 years ago

1.0.0-alpha.56

5 years ago

1.0.0-alpha.57

5 years ago

1.0.0-alpha.52

5 years ago

1.0.0-alpha.51

5 years ago

1.0.0-alpha.54

5 years ago

1.0.0-alpha.53

5 years ago

1.0.0-alpha.55

5 years ago

1.0.0-alpha.50

5 years ago

1.0.0-alpha.49

5 years ago

1.0.0-alpha.48

5 years ago

1.0.0-alpha.43

5 years ago

1.0.0-alpha.42

5 years ago

1.0.0-alpha.45

5 years ago

1.0.0-alpha.44

5 years ago

1.0.0-alpha.47

5 years ago

1.0.0-alpha.46

5 years ago

1.0.0-alpha.38

5 years ago

1.0.0-alpha.37

5 years ago

1.0.0-alpha.39

5 years ago

1.0.0-alpha.41

5 years ago

1.0.0-alpha.40

5 years ago

1.0.0-alpha.34

5 years ago

1.0.0-alpha.33

5 years ago

1.0.0-alpha.36

5 years ago

1.0.0-alpha.35

5 years ago

1.0.0-alpha.32

5 years ago

1.0.0-alpha.30

5 years ago

1.0.0-alpha.27

5 years ago

1.0.0-alpha.26

5 years ago

1.0.0-alpha.22

5 years ago

1.0.0-y.0

5 years ago

1.0.0-alpha.18

5 years ago

1.0.0-alpha.13

5 years ago

1.0.0-alpha.12

5 years ago

1.0.0-alpha.11

5 years ago

1.0.0-alpha.10

6 years ago

1.0.0-alpha.9

6 years ago

1.0.0-alpha.8

6 years ago

1.0.0-alpha.7

6 years ago

1.0.0-alpha.6

6 years ago

1.0.0-alpha.5

6 years ago

1.0.0-alpha.4

6 years ago