1.5.0 • Published 1 year ago

drpc-sdk v1.5.0

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

DRPC SDK

Client-side library for working with DRPC (drpc.org). It's responsibility to communicate with DRPC and also to check provided signatures for response data, validating data authenticity. Supports node and browser.

Installation

npm install drpc-sdk

Example

import { HTTPApi } from 'drpc-sdk';

async function getBlockHeight() {
  let api = new HTTPApi({
    api_key: 'api key',
    url: 'https://drpc.org/api',
    provider_ids: ['test'],
    provider_num: 1,
  });

  // single request
  let blockheight = await api.call({
    method: 'eth_blockNumber',
    params: [],
  });

  // batch request
  let batch = await api.callMulti([
    {
      method: 'eth_blockNumber',
      params: [],
    },
    {
      method: 'eth_getBlockByNumber',
      params: ['0x100001'],
    },
  ]);
}

Documentation

API Documentation

Using in browser

This module is written to work in node and browser. Because of that, by default webpack and other bundlers will try to bundle node dependencies (like node-fetch, etc). However, if you use webpack you can just define constant and it will eliminate any non-browser code.

{
  // ....
  plugins: [
    new webpack.DefinePlugin({
      __isBrowser__: 'true',
    }),
  ],
};

Web3.js provider

If you're using web3.js, drpc-sdk exposes the provider

import { HttpDrpcProvider } from 'drpc-sdk/dist/esm/providers/web3';
// for cjs
// import { DrpcProvider } from 'drpc-sdk/dist/cjs/providers/web3';

async function getBlock(tag) {
  let state = provider({
    api_key: 'api key',
    url: 'https://drpc.org/api',
    provider_ids: ['test'],
    provider_num: 1,
  });
  // or WsDrpcProvider for websockets
  let provider = new HttpDrpcProvider(state);
  let web3 = new Web3(provider);

  let result = await web3.eth.getBlockNumber();
}

Ethers.js provider

If you're using ethers.js, drpc-sdk exposes the provider

import { DrpcProvider } from 'drpc-sdk/dist/esm/providers/ethers';
// for cjs
// import { DrpcProvider } from 'drpc-sdk/dist/cjs/providers/ethers';

async function getBlock(tag) {
  let state = provider({
    api_key: 'api key',
    url: 'https://drpc.org/api',
    provider_ids: ['test'],
    provider_num: 1,
  });
  let provider = new DrpcProvider(state);
  let block = await provider.getBlock(tag);
}
1.5.0

1 year ago

1.4.0

1 year ago

1.3.4

2 years ago

1.3.3

2 years ago

1.3.2

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago

0.3.20

2 years ago

0.3.19

2 years ago

0.3.18

2 years ago

0.3.17

2 years ago

0.3.16

2 years ago

0.3.15

2 years ago

0.3.14

2 years ago

0.3.13

2 years ago

0.3.12

2 years ago

0.3.11

2 years ago

0.3.10

2 years ago

0.3.9

2 years ago

0.3.8

2 years ago

0.3.7

2 years ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.4

2 years ago

0.3.3

2 years ago

0.3.1

2 years ago

0.3.0

2 years ago

0.2.4

2 years ago

0.2.2

2 years ago

0.2.0

2 years ago

0.1.0

2 years ago