conflux-web-providers
ConfluxWeb module to handle requests to external providers.
Last updated 8 months ago by ypliu .
LGPL-3.0 · Repository · Original npm · Tarball · package.json
$ cnpm install conflux-web-providers 
SYNC missed versions from official npm registry.

conflux-web-providers

This is a sub package of ConfluxWeb.js

Installation

npm install conflux-web-providers

Usage Examples

HttpProvider

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

import {HttpProvider} from 'conflux-web-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

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

IpcProvider

import {IpcProvider} from 'conflux-web-providers';
import net from 'net';

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

BatchRequest

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

import {ProviderResolver, BatchRequest} 'conflux-web-providers';

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

batchRequest.add(confluxWeb.cfx.getBalance.request(
    '0x0000000000000000000000000000000000000000',
    'latest_state',
    callback
));

await batchRequest.execute();

ProviderDetector

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

import {ProviderDetector} from 'conflux-web-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 conflux-web has internally just one provider interface and we have no direct dependency to third party providers.

import {ProviderResolver} 'conflux-web-providers';

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

Types

All the typescript typings are placed in the types folder.

Current Tags

  • 1.36.7-alpha.0                                ...           latest (8 months ago)

39 Versions

  • 1.36.7-alpha.0                                ...           8 months ago
  • 1.36.6-alpha.0                                ...           8 months ago
  • 1.36.5-alpha.0                                ...           8 months ago
  • 1.36.4-alpha.0                                ...           8 months ago
  • 1.36.3-alpha.0                                ...           8 months ago
  • 1.36.2-alpha.0                                ...           8 months ago
  • 1.36.1-alpha.0                                ...           8 months ago
  • 1.36.0-alpha.0                                ...           8 months ago
  • 1.35.1-alpha.0                                ...           9 months ago
  • 1.35.0                                ...           a year ago
  • 0.1.35-alpha.2                                ...           a year ago
  • 0.1.35-alpha.1                                ...           a year ago
  • 0.1.35-alpha.0                                ...           a year ago
  • 0.1.34                                ...           a year ago
  • 0.1.33                                ...           a year ago
  • 0.1.33-alpha.0                                ...           a year ago
  • 0.1.32-alpha.0                                ...           a year ago
  • 0.1.30-alpha.0                                ...           a year ago
  • 0.1.29-alpha.0                                ...           a year ago
  • 0.1.15-alpha.0                                ...           a year ago
  • 0.1.14-alpha.0                                ...           a year ago
  • 0.1.13-alpha.0                                ...           a year ago
  • 0.1.12-alpha.0                                ...           a year ago
  • 0.1.10-alpha.0                                ...           a year ago
  • 0.1.9                                ...           a year ago
  • 0.1.8                                ...           a year ago
  • 0.1.7                                ...           a year ago
  • 0.1.6                                ...           a year ago
  • 0.1.5                                ...           a year ago
  • 0.1.4                                ...           a year ago
  • 0.1.1                                ...           2 years ago
  • 0.1.1-alpha.0                                ...           2 years ago
  • 0.1.0-alpha.4                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
  • 0.1.0-alpha.3                                ...           2 years ago
  • 0.1.0-alpha.2                                ...           2 years ago
  • 0.1.0-alpha.1                                ...           2 years ago
  • 0.1.0-alpha.0                                ...           2 years ago
  • 0.0.1                                ...           2 years ago

Copyright 2014 - 2016 © taobao.org |