@oone-lido-sdk/providers
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Providers

Providers for Lido Finance projects. Part of Lido JS SDK

A Provider is an abstraction of a connection to the Ethereum network, providing a concise, consistent interface to standard Ethereum node functionality. More details in the ethers docs.

Install

yarn add @oone-lido-sdk/providers

RPC providers

Source

Each getter returns a cached Provider instance.

getRpcProvider

Returns a JsonRpcProvider instance.

import { CHAINS } from '@oone-lido-sdk/constants';
import { getRpcProvider } from '@oone-lido-sdk/providers';

const provider = getRpcProvider(CHAINS.Mainnet, '/rpc/url');

getRpcBatchProvider

Returns an instance of batch version of JsonRpcProvider.

import { CHAINS } from '@oone-lido-sdk/constants';
import { getRpcBatchProvider } from '@oone-lido-sdk/providers';

const batchProvider = getRpcBatchProvider(CHAINS.Mainnet, '/rpc/url');

getStaticRpcProvider

Returns a StaticJsonRpcProvider instance.

import { CHAINS } from '@oone-lido-sdk/constants';
import { getStaticRpcProvider } from '@oone-lido-sdk/providers';

const staticProvider = getStaticRpcProvider(CHAINS.Mainnet, '/rpc/url');

getStaticRpcBatchProvider

Returns an instance of batch version of StaticJsonRpcProvider.

import { CHAINS } from '@oone-lido-sdk/constants';
import { getStaticRpcBatchProvider } from '@oone-lido-sdk/providers';

const staticProvider = getStaticRpcBatchProvider(CHAINS.Mainnet, '/rpc/url');

Cache

To get another provider instance, getters have a third optional parameter cacheSeed.

Calls without cacheSeed or with the same cacheSeed return the same providers:

const providerFirst = getRpcBatchProvider(CHAINS.Mainnet, '/rpc/url', 1);
const providerSecond = getRpcBatchProvider(CHAINS.Mainnet, '/rpc/url', 1);

providerFirst === providerSecond; // true

Calls with different cacheSeed return different providers:

const providerFirst = getRpcBatchProvider(CHAINS.Mainnet, '/rpc/url', 1);
const providerSecond = getRpcBatchProvider(CHAINS.Mainnet, '/rpc/url', 2);

providerFirst !== providerSecond; // true

Of course, if the cacheSeed is the same, but chainId or url are different the result providers will also be different:

const providerFirst = getRpcBatchProvider(CHAINS.Mainnet, '/rpc/url', 1);
const providerSecond = getRpcBatchProvider(
  CHAINS.Mainnet,
  '/another/rpc/url',
  1,
);

providerFirst !== providerSecond; // true, because the urls are different

Package Sidebar

Install

npm i @oone-lido-sdk/providers

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

12.9 kB

Total Files

15

Last publish

Collaborators

  • pavel.solovyev