Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@drpcorg/drpc-sdk

Package Overview
Dependencies
Maintainers
2
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@drpcorg/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.6.0
  • npm
  • Socket score

Version published
Weekly downloads
4
increased by33.33%
Maintainers
2
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({
    dkey: '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({
    dkey: '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({
    dkey: '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 07 Mar 2023

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc