Skip to content

Agilefreaks/lava-sdk

 
 

Repository files navigation


Logo

Lava SDK - ALPHA

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

Roadmap

The SDK is currently in the Alpha stage and is not production-ready for all usecases.

Roadmap highlights:

  1. Send Relays per Lava Pairing
  2. Find seed providers for the initial connection
  3. EtherJS Integration
  4. Ability to run in the browser without compromising keys
  5. High throughput via session management
  6. More libraries integrations (Cosmjs, web3.js...)
  7. Other Lava consensus implementations (e.g. QoS, data reliability, ...)

(back to top)

Installation

Important Version Control

For Example

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


Prerequisites (Alpha version)

SDK setup requires additional steps at the moment, but we're working on minimizing prerequisites as we progress through the roadmap.

  1. Create a wallet on the Lava Testnet, have LAVA tokens
  2. Stake in the chain you want to access
  3. 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

yarn add @lavanet/lava-sdk

(back to top)

Usage

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 specified chainID.

  • 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 be tendermintRPC or rest. For evm compatible chains jsonRPC or rest. 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 specified chainID and rpcInterface 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 is testnet.

  • geolocation is an optional field that specifies the geolocation which will be used. Default value is 1 which represents North America providers. Besides North America providers, lava supports EU providers on geolocation 2.

  • lavaChainId is an optional field that specifies the chain id of the lava network. Default value is lava-testnet-1 which represents Lava testnet.


TendermintRPC / JSON-RPC interface:

  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

Rest API interface:

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

(back to top)

Troubleshooting

Webpack >= 5

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.

Create-react-app solution

  1. 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
  1. 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;
};
  1. 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"
},

Angular solution (TBD)

(back to top)

Contributors Forks Stargazers Issues Apache 2 License LinkedIn

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 53.2%
  • JavaScript 46.6%
  • Shell 0.2%