This project is being slowly deprecated and may not receive further updates. Check out modern Lido SDK to access latest functionality. It is actively maintained and is built for interacting with Lido Protocol.
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.
yarn add @lido-sdk/providers
Each getter returns a cached Provider instance.
Returns a JsonRpcProvider instance.
import { CHAINS } from '@lido-sdk/constants';
import { getRpcProvider } from '@lido-sdk/providers';
const provider = getRpcProvider(CHAINS.Mainnet, '/rpc/url');
Returns an instance of batch version of JsonRpcProvider.
import { CHAINS } from '@lido-sdk/constants';
import { getRpcBatchProvider } from '@lido-sdk/providers';
const batchProvider = getRpcBatchProvider(CHAINS.Mainnet, '/rpc/url');
Returns a StaticJsonRpcProvider instance.
import { CHAINS } from '@lido-sdk/constants';
import { getStaticRpcProvider } from '@lido-sdk/providers';
const staticProvider = getStaticRpcProvider(CHAINS.Mainnet, '/rpc/url');
Returns an instance of batch version of StaticJsonRpcProvider.
import { CHAINS } from '@lido-sdk/constants';
import { getStaticRpcBatchProvider } from '@lido-sdk/providers';
const staticProvider = getStaticRpcBatchProvider(CHAINS.Mainnet, '/rpc/url');
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