1.0.4-alpha.3 • Published 3 years ago

youchain-providers v1.0.4-alpha.3

Weekly downloads
81
License
LGPL-3.0
Repository
github
Last release
3 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

3 years ago

1.0.4-alpha.1

3 years ago

1.0.4-alpha.0

3 years ago

1.0.4-alpha.2

3 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.1-alpha.1

4 years ago

1.0.1-alpha.0

4 years ago

1.0.0

4 years ago

1.0.0-alpha.84

4 years ago

1.0.0-alpha.83

4 years ago

1.0.0-alpha.82

4 years ago

1.0.0-alpha.81

4 years ago

1.0.0-alpha.78

4 years ago

1.0.0-alpha.79

4 years ago

1.0.0-alpha.80

4 years ago

1.0.0-alpha.76

4 years ago

1.0.0-alpha.77

4 years ago

1.0.0-alpha.74

4 years ago

1.0.0-alpha.73

4 years ago

1.0.0-alpha.75

4 years ago

1.0.0-alpha.72

4 years ago

1.0.0-alpha.71

4 years ago

1.0.0-alpha.65

4 years ago

1.0.0-alpha.64

4 years ago

1.0.0-alpha.63

4 years ago

1.0.0-alpha.62

4 years ago

1.0.0-alpha.61

4 years ago

1.0.0-alpha.60

4 years ago

1.0.0-alpha.59

4 years ago

1.0.0-alpha.58

4 years ago

1.0.0-alpha.56

4 years ago

1.0.0-alpha.57

4 years ago

1.0.0-alpha.52

4 years ago

1.0.0-alpha.51

4 years ago

1.0.0-alpha.54

4 years ago

1.0.0-alpha.53

4 years ago

1.0.0-alpha.55

4 years ago

1.0.0-alpha.50

4 years ago

1.0.0-alpha.49

4 years ago

1.0.0-alpha.48

4 years ago

1.0.0-alpha.43

4 years ago

1.0.0-alpha.42

4 years ago

1.0.0-alpha.45

4 years ago

1.0.0-alpha.44

4 years ago

1.0.0-alpha.47

4 years ago

1.0.0-alpha.46

4 years ago

1.0.0-alpha.38

4 years ago

1.0.0-alpha.37

4 years ago

1.0.0-alpha.39

4 years ago

1.0.0-alpha.41

4 years ago

1.0.0-alpha.40

4 years ago

1.0.0-alpha.34

4 years ago

1.0.0-alpha.33

4 years ago

1.0.0-alpha.36

4 years ago

1.0.0-alpha.35

4 years ago

1.0.0-alpha.32

4 years ago

1.0.0-alpha.30

4 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

5 years ago

1.0.0-alpha.9

5 years ago

1.0.0-alpha.8

5 years ago

1.0.0-alpha.7

5 years ago

1.0.0-alpha.6

5 years ago

1.0.0-alpha.5

5 years ago

1.0.0-alpha.4

5 years ago