🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

drpc-sdk

Package Overview
Dependencies
Maintainers
1
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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.

1.5.0
latest
npm
Version published
Weekly downloads
8
-11.11%
Maintainers
1
Weekly downloads
 
Created
Source

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);
}

FAQs

Package last updated on 29 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts