Access Web3 APIs, the Lava way π
JavaScript/TypeScript SDK reference implementation designed for developers looking for access through the Lava Network. It can be added to your app/dapp and run in browsers to provide multi-chain peer-to-peer access to blockchain APIs.
The SDK is currently in the Alpha stage and is not production-ready for all usecases.
Roadmap highlights:
Send Relays per Lava PairingβFind seed providers for the initial connectionβEtherJS Integrationβ- Ability to run in the browser without compromising keys
- High throughput via session management
- More libraries integrations (Cosmjs, web3.js...)
- Other Lava consensus implementations (e.g. QoS, data reliability, ...)
-
Please check the current Lava node version before installing the lava-sdk.
-
Make sure you are using the
"Latest"tag. You can check the latest releases here: https://github.com/lavanet/lava/releases -
lava-sdk releases can be found here: https://github.com/lavanet/lava-sdk/releases or in the npm official site: https://www.npmjs.com/package/@lavanet/lava-sdk
If lava latest release version is v0.8.0 or any minor version such as v0.8.1 β‘οΈ sdk version will be v0.8.0
SDK setup requires additional steps at the moment, but we're working on minimizing prerequisites as we progress through the roadmap.
- Create a wallet on the Lava Testnet, have LAVA tokens
- Stake in the chain you want to access
- Stake in Lava chain
Need help? We've got you covered π» Head over to our Discord channel #developers and we'll provide testnet tokens and further support
yarn add @lavanet/lava-sdknpm install @lavanet/lava-sdkA single instance of the SDK establishes a connection with a specific blockchain network using a single RPC interface. Need multiple chains or use multiple RPC interfaces? Create multiple instances.
To use the SDK, you will first need to initialize it.
const lavaSDK = await new LavaSDK({
privateKey: privKey,
chainID: chainID,
rpcInterface: rpcInterface, // Optional
pairingListConfig: localConfigPath, // Optional
network: network; // Optional
geolocation: geolocation; // Optional
});-
privateKeyparameter is required and should be the private key of the staked Lava client for the specifiedchainID. -
chainIDparameter is required and should be the ID of the chain you want to query. You can find all supported chains with their IDs supportedChains -
rpcInterfaceis an optional field representing the interface that will be used for sending relays. For cosmos chains it can betendermintRPCorrest. For evm compatible chainsjsonRPCorrest. You can find the list of all default rpc interfaces supportedChains -
pairingListConfigis an optional field that specifies the lava pairing list config used for communicating with lava network. Lava SDK does not rely on one centralized rpc for querying lava network. It uses a list of rpc providers to fetch list of the providers for specifiedchainIDandrpcInterfacefrom lava network. If not pairingListConfig set, the default list will be used default lava pairing list -
networkis an optional field that specifies the network from pairingListConfig which will be used. Default value ismainnet. -
geolocationis an optional field that specifies the geolocation which will be used. Default value is1which represents North America providers. Besides North America providers, lava supports EU providers on geolocation2.
const blockResponse = await lavaSDK.sendRelay({
method: "block",
params: ["5"],
});Here, method is the RPC method and params is an array of strings representing parameters for the method.
You can find more examples for tendermintRPC sendRelay calls TendermintRPC examples
const data = await lavaSDK.sendRelay({
method: "GET",
url: "/cosmos/bank/v1beta1/denoms_metadata",
data: {
"pagination.count_total": true,
"pagination.reverse": "true",
},
});In this case, method is the HTTP method (either GET or POST), url is the REST endpoint, and data is the query data.
You can find more examples for rest sendRelay calls Rest examples
If you are using create-react-app version 5 or higher, or Angular version 11 or higher, you may encounter build issues. This is because these versions use webpack version 5, which does not include Node.js polyfills.