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.
Docs: https://bit.ly/43pyhwA
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-sdk
A 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
});
-
privateKey
parameter is required and should be the private key of the staked Lava client for the specifiedchainID
. -
chainID
parameter is required and should be the ID of the chain you want to query. You can find all supported chains with their IDs supportedChains -
rpcInterface
is an optional field representing the interface that will be used for sending relays. For cosmos chains it can betendermintRPC
orrest
. For evm compatible chainsjsonRPC
orrest
. You can find the list of all default rpc interfaces supportedChains -
pairingListConfig
is 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 specifiedchainID
andrpcInterface
from lava network. If not pairingListConfig set, the default list will be used default lava pairing list -
network
is an optional field that specifies the network from pairingListConfig which will be used. Default value istestnet
. -
geolocation
is an optional field that specifies the geolocation which will be used. Default value is1
which represents North America providers. Besides North America providers, lava supports EU providers on geolocation2
. -
lavaChainId
is an optional field that specifies the chain id of the lava network. Default value islava-testnet-1
which represents Lava testnet.
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.
- Install react-app-rewired and the missing modules:
yarn add --dev react-app-rewired crypto-browserify stream-browserify browserify-zlib assert stream-http https-browserify os-browserify url buffer process net tls bufferutil utf-8-validate path-browserify
- Create
config-overrides.js
in the root of your project folder, and append the following lines:
const webpack = require("webpack");
module.exports = function override(config) {
const fallback = config.resolve.fallback || {};
Object.assign(fallback, {
crypto: require.resolve("crypto-browserify"),
stream: require.resolve("stream-browserify"),
assert: require.resolve("assert"),
http: require.resolve("stream-http"),
https: require.resolve("https-browserify"),
os: require.resolve("os-browserify"),
url: require.resolve("url"),
zlib: require.resolve("browserify-zlib"),
fs: false,
bufferutil: require.resolve("bufferutil"),
"utf-8-validate": require.resolve("utf-8-validate"),
path: require.resolve("path-browserify"),
});
config.resolve.fallback = fallback;
config.plugins = (config.plugins || []).concat([
new webpack.ProvidePlugin({
process: "process/browser",
Buffer: ["buffer", "Buffer"],
}),
]);
config.ignoreWarnings = [/Failed to parse source map/];
config.module.rules.push({
test: /\.(js|mjs|jsx)$/,
enforce: "pre",
loader: require.resolve("source-map-loader"),
resolve: {
fullySpecified: false,
},
});
return config;
};
- In the
package.json
change the script for start, test, build and eject:
"scripts": {
"start": "react-app-rewired start",
"build": "react-app-rewired build",
"test": "react-app-rewired test",
"eject": "react-scripts eject"
},