Using LavaSDK
π‘οΈ The Frontendβ
β οΈ The Problem: Using private keys on the frontend without special provisions is inherently unsafe. In ordinary development scenarios, private keys from a user can be leaked through the browser.
β
The Solution: Lava uses a unique solution called badges
to solve these limitations. A badge
consists of several parts and is used in lieu of a private key. It must, however, be signed by an external server that holds the relevant authorizing party's private key. The default Badge Server is hosted by Lava and requires no additional configurations.
π Get Started: You can get started right from the Lava Gateway! We recognize that a hosted solution is not ideal for every use case. Users who are interested in accomplishing the highest levels of decentralization may run their own badge server.
βͺοΈ Recommended Flowβ
Although you can host your own badge server, the easiest way to get started is through Lava's Gateway.
Sign up to the Gateway. ππΏRegister now if you havenβt already!
Create a Project and Select your APIs!
Open an API and click LavaSDK.
Install the SDK into your project ->
npm install @lavanet-lava-sdk
Copy & paste your code snippet into your code.
π Badgesβ
Usage βοΈβ
Badges are objects passed to the SDK instance which allow a user to forgo the usage of private keys. A badge has the following format:
const myBadge = {
badgeServerAddress: "https://badges.lavanet.xyz", // Or your own Badge-Server URL
projectId: "<from gateway>" //input your project ID from the Gateway or custom setup
};
A user can initialize the SDK using a badge instead of a privatekey
const lavaSDK = await LavaSDK.create({
badge: myBadge,
chainID: "LAV1",
rpcInterface: "rest",
});
And make calls all the same - no privatekeys exposed!
const info = await lavaSDK.sendRelay({
method: "GET",
url: "/node_info",
});
π That's it. For most users, there is no additional information required to successfully use LavaSDK on the front end!